General question about how do I loop this process?

조회 수: 1 (최근 30일)
Laurentiu Galan
Laurentiu Galan 2012년 1월 10일
%Pull all the Data into Matlab to Pull each line and Read the contents back into an array
fid = fopen('C:\Users\Laurentiu Galan\Desktop\pca1.csv');
tline = fgetl(fid);
while ischar(tline)
disp(tline)
tline = fgetl(fid);
end
fclose(fid);
Hello, I am trying to several things at once in the code and was wondering if you could give me some generic insight into how I could continue with this process.
I've run this code and was able to read the the individual lines into matlab. How do i actually access each individual line? I need to parse some data into each line and was wondering how to loop it
For example: if I wanted the 2645 line, how do I get?
Thanks!

채택된 답변

Andrew Newell
Andrew Newell 2012년 1월 10일
It depends. If you want just line 2645, you could do the following:
for ii=1:2644
fgetl(fid);
end
tline = fgetl(fid);
If you want to store all the lines, you could save them in a cell array:
tline = cell(3000,1); % or whatever size you need
ii=1;
while ischar(tline)
tline{ii} = fgetl(fid);
ii = ii+1;
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 1월 10일
Right. In particular, there is no way to just "go" to a specific line (no unless you know *exactly* which byte number it is in the file.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by