Saving variables in the loop.

1 次查看(过去 30 天)
Hi Im using fgets to display every line in the file.
fid = fopen('file');
tline = fgets(fid);
while ischar(tline)
L = (tline);
tline = fgets(fid);
disp(tline)
end
I would like to save every line in the workspace in sequence as L1, L2, L3 ...
Can You propose me a solution?
Thank You.

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-1-28
编辑:Azzi Abdelmalek 2013-1-28
fid = fopen('file');
line1 = fgetl(fid);
res=line1;
while ischar(line1)
line1 = fgetl(fid);
res =char(res,line1)
end
fclose(fid);
  5 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2013-1-28
编辑:Azzi Abdelmalek 2013-1-28
fid = fopen('file');
line1 = fgetl(fid);
res=line1;
k=0
while ischar(line1)
k=k+1;
line1 = fgetl(fid);
assignin('base',sprintf('L%d',k),line1)
end
fclose(fid);
ZK
ZK 2013-1-28
Thank You very much, working great.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by