質問

I'm trying to textscan a file and read a single line until the end of it, undependently of the number of elements in that line.

My file is a .txt file formatted like this :

602,598,302,456,1023,523,....
293,291,566,331,987,56,....
589,202,429,2911,294,567,...

And so on. I have the number of the line, and all lines have the same number of elements, but it can vary from one file to another.

I wrote something like:

fid = fopen('somefile.txt');
C = textscan(fid, formatSpec,'HeaderLines',Row-1);
TheLine = C{1};
fclose(fid);

X = numel(TheLine);
plot(1:X,TheLine);

I really don't know what to type in the formatSpec field. I've tried a few things in the way of %[^\n] but I didn't get much sucess.

役に立ちましたか?

解決

Try this -

C = textscan(fid, '%d,','HeaderLines',Row-1);

Row will specify the row of data that you want to extract from the text file.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top