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.
0 个评论
采纳的回答
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
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!