Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: determine col num from column headers
Date: Wed, 13 Aug 2008 07:58:02 +0000 (UTC)
Organization: Pierburg GmbH
Lines: 66
Message-ID: <g7u46a$83j$1@fred.mathworks.com>
References: <g7q2bb$ffi$1@fred.mathworks.com> <g7rj59$g4m$1@fred.mathworks.com> <g7sq09$rj2$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1218614282 8307 172.30.248.35 (13 Aug 2008 07:58:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 13 Aug 2008 07:58:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 872224
Xref: news.mathworks.com comp.soft-sys.matlab:485211



"Keli " <kalark@ford.com> wrote in message <g7sq09$rj2
$1@fred.mathworks.com>...
[..]
> A better example:
> I have just loaded a data file with a matrix 
> called "datafile1" (sized at <148x482 double>), and the 
> corresponding column names is in "colheaders" array (size 
> <1x482 cell>). I know the exact column names, but I must 
> open the colheaders array and scroll to find where a 
> target column is, since the data matrix doesn't have 
> column names.
>    For example: the column name/header "Torque" is in 
> column # 422 of the 'colheader' array. The corresponding 
> torque data is in the matrix "datafile1" column no 422. 
> The end goal is to use this column number (422) to read 
> the Torque data into a seperate vector to be further 
> manipulated later. If I double click on the colheaders 
> cell named 'Torque', the array editor title is colheaders
> {1,422}.   
> 
> Herein lies the problem.  I have to verify all files in 
> this data set have the 'Torque' data stored in column 
422 -
> or determine which column it is stored in.  Once 
> determined, the torque data from each file will be saved 
> as a seperate variable.  If I only had to manual verify 
> this in 1 data set (approx 25 files), it would be okay.  
> Currently however, it is 125 files, with more on the way. 
> 
> Also: I believe the string data in column headers is 
> delimited by single quote (') not semicolon (;).  So 
> modifing the code to " delim = '''; " does not work.  Am 
> also unsuccessful with strfind:
> 
> strfind(colheaders,'Torque')
> ans = 
> 
>   Columns 1 through 9
> 
>      []     []     []  ...
>   Columns 442 through 450
> 
>      []     []     []     []     []
> etc.
> 
> 
> Hope this helps expain what is going on.  Thanks so much 
> for all your time.
> 

So your colheaders variable is a cell array of strings. 
Then I'd expect a non-empty element somewhere in the 
resulting cell array of strfind. 
Besides, use find(strcmp( rather than strfind( on the cell 
array. Perhaps you have to care about some extra whitespace 
around your column names.
The following example works:

    colheaders = {' Freq','  Torque ','Temp '};
    cleanColheaders = strtrim(colheaders);
    idx = find(strcmp('Torque',cleanColheaders));
    % idx = 2

Check if you need to use strcmpi instead of strcmp.
Does this work for you as well? If not, can you find out 
why?