Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: determine col num from column headers
Date: Tue, 12 Aug 2008 08:55:05 +0000 (UTC)
Organization: Pierburg GmbH
Lines: 63
Message-ID: <g7rj59$g4m$1@fred.mathworks.com>
References: <g7q2bb$ffi$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1218531305 16534 172.30.248.38 (12 Aug 2008 08:55:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 12 Aug 2008 08:55:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 872224
Xref: news.mathworks.com comp.soft-sys.matlab:485023



"Keli " <krishnakeli@gmail.com> wrote in message 
<g7q2bb$ffi$1@fred.mathworks.com>...
> Hello!
> I have 5 data sets containing 25 files each with 465 to 
> 517 columns, and I need to read 4 specific columns from 
> each file. The files are loaded from *.csv into 
> seperate 'colheader' string array and the data matrix.  
> While each data set tends to have the same number of 
> columns, thus far I need to manually view 'colheader' 
data 
> string from each file in the data set to be certain the 
> target columns are indeed the same column number.  Once I 
> am certain of the column number I load this column into a 
> seperate vector to use in other Matlab operations. Any 
> suggestions on how can I determine the column number? Can 
> I use the column headers (the 'colheader' string) to 
> locate the specific column numbers?  

Hi,

we need more information about your colheader string, but 
here's a hint to an automation routine that might work, as 
a best guess:

You know the exact distinct column title strings appearing 
in your header line string

    myColumnNames = {'Val1','Val2','Val3','Val4'};

If your header string contains more than one line, you 
should extract the line that contains your column names. 
Maybe you can identify the lines by the positions of a line 
break character:

    lineBreakPos = strfind(colheader,char(10));

Find out somehow which line has the names, perhaps you know 
it beforehand. Assuming the k-th line is the line of 
interest, do something like:

    columnNameLine = colheader(lineBreakPos(k-1)+1: 
lineBreakPos(k)-1 );

(take obvious precautions if it is the first or last line 
in colheader)

Most probably there is a distinct delimiter (Tab, 
space, ';', ',' ...) between the column name strings. Find 
its positions in the line ...

    delim = ';';
    delimPos = strfind(columnNameLine,delim);

find out the positions of your column name strings ...

    namePos(n) = strfind(columnNameLine,myColumnNames(n));

and compare them to the delimiter positions to make out the 
corresponding column index of your data matrix.

I hope this gets you started.
Best regards
Andres