Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: file length
Date: Wed, 3 Jun 2009 22:54:01 +0000 (UTC)
Organization: Universit&#228;t Heidelberg
Lines: 27
Message-ID: <h06uu9$hmn$1@fred.mathworks.com>
References: <h05vlj$csf$1@fred.mathworks.com> <h06751$f6f$1@fred.mathworks.com> <h068re$9b5$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1244069641 18135 172.30.248.37 (3 Jun 2009 22:54:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 3 Jun 2009 22:54:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869888
Xref: news.mathworks.com comp.soft-sys.matlab:544669


Dear Dominic!

> The files are all in ASCII format I believe. I created them using dlmwrite so that is what format the should be in. I am a bit confused as to how I can get the number of elements from sscanf without loading the file into the workspace.

My suggested FGETL method reads just the first line of the file:
  FID = fopen(FileName, 'rb');
  Line1 = fgetl(FID);
  fclose(FID);
  Data = sscanf(Line1);
  NumberOfColums = length(Data);

Nevertheless, if I read your original question, I find, that you want the number of **rows**, not columns...

Beside the smart WC command, you could try this function in pure Matlab:

function nRow = CountLines(FileName)
FID = fopen(FileName, 'rb');  % ADD CHECK FOR: FID==-1
nRow = 0;
while ischar(fgets(FID))
  nRow = nRow + 1;
end
fclose(FID);
return;

This is faster than loading the file into the workspace, because the ASCII lines are not parsed from text to doubles.

Good luck, Jan