I need to use 'for loop' to read the names from a text file using 'fgetl' function. How do I do that?

17 次查看(过去 30 天)
There is a list of 80 test subject names in a text file, and I have to use the for loop function to read the names of the first 40 subjects using fgetl function. How do I write the code in MATLAB.
Thanks!!

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-6-2
编辑:Azzi Abdelmalek 2013-6-2
fid = fopen('filename.txt');
line1 = fgetl(fid);
res=line1;
while ischar(line1)
if ischar(line)
res =char(res,line1)
end
line1 = fgetl(fid);
end
fclose(fid);
  3 个评论
Image Analyst
Image Analyst 2013-6-2
Reading the help is always a good idea. In there is this example:
Examples
Read and display the file fgetl.m one line at a time:
fid = fopen('fgetl.m');
tline = fgetl(fid);
while ischar(tline)
disp(tline)
tline = fgetl(fid);
end
fclose(fid);

请先登录,再进行评论。

更多回答(1 个)

anukriti dureha
anukriti dureha 2013-6-2

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by