Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe03.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.16 (Windows/20080708)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: Fastest way to get the number of lines
References: <g8v5cv$1us$1@fred.mathworks.com> <Z8Gsk.114613$nD.80388@pd7urf1no> <g9037b$efl$1@fred.mathworks.com> <g90jtn$p9g$1@z-news.pwr.wroc.pl> <gap9vn$jqf$1@fred.mathworks.com>
In-Reply-To: <gap9vn$jqf$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 37
Message-ID: <cfWzk.11670$rV4.5062@newsfe03.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe03.iad 1221603400 24.79.146.116 (Tue, 16 Sep 2008 22:16:40 UTC)
NNTP-Posting-Date: Tue, 16 Sep 2008 22:16:40 UTC
Date: Tue, 16 Sep 2008 17:17:05 -0500
Xref: news.mathworks.com comp.soft-sys.matlab:490542


Pete sherer wrote:
> Similarly instead of counting the number of lines in the file, can the PERL 
> code be modified to find the first row (of the first column only) that 
> contains a specified value?

> For example, if the file looks like
> 2,45,56,7767,76,565.5,...
> 23,454,556,74767,476,5465.5,...
> 56,15,16,1767,176,1565.5,...
> 678,45,5,67,6,0.5,...
> 845,11,22,45,32,2.5,...
> ...

> For example, I want to know the line number that the first column contains 678, 
> then the line number should be 4.


Yes. For example, store the below two lines in findvalline.pl

$targetval = shift @ARGV;
while (<>) { /^$targetval,/ && do { print $.,"\n"; break } }

Then to make a matlab call to find the value N in file XYZ.csv

linenum = str2num( perl('findvalline.pl', num2str(N), 'XYZ.csv') );
if isemtpy(linenum); error('no match'); end


But be careful if your target is not an integer: num2str() will
not necessarily round or truncate the same way as is in the file.
You may wish to use a more sophisticated way of determining
the matching string than using num2str().

-- 
Q = quotation(rand);
if isempty(Q); error('Quotation server filesystem problems')
else sprintf('%s',Q), end