[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: textread...read first and last row
From: |
Andrew Janke |
Subject: |
Re: textread...read first and last row |
Date: |
Sat, 16 Mar 2019 09:21:04 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 |
On 3/16/19 7:18 AM, turbofib wrote:
hi,
look that
01/04/2008 0.00000 0 0.00000 0.00000 0
02/04/2009 -600.00000 0 0.00000 931.25000 1
03/04/2010 750.00000 1 0.00000 1362.50000 2
04/04/2011 12.50000 1 -18.75000 1000.00000 2
05/04/2012 0.00000 0 0.00000 0.00000 2
06/04/2013 -256.25000 1 12.50000 343.75000 2
07/04/2014 -6.25000 1 0.00000 575.00000 2
08/04/2015 -1100.00000 0 12.50000 1556.25000 2
i want catch the first and the last row with textread (i want catch only
date)
the number of lines is not fixed
here i catch the first row (year 2008)
[datInizio]=textread (nomeFileDaEsaminare, "%s ",1);
how can i code to catch the last row?(year 2015)
thank to help me
You can use fopen()/fgetl() to do line-oriented input. Something like this:
fid = fopen(nomeFileDaEsaminare);
firstLine = fgetl(fid);
lastLine = [];
while true
line = fgetl(fid);
if line == -1
break
end
lastLine = liine;
end
fclose(fid);
You could also use textscan() to read the whole file in tabular format,
and then extract the first and last rows of data. This is probably more
useful and flexible for you.
fid = fopen(nomeDileDaEsaminare
c = textscan(fid, "%s %f %f %f %f %f")
fclose(fid);
firstLineData = c(1,:);
lastLineData = c(end,:);
Cheers,
Andrew