MATLAB: Saving variables in the loop.

loop fgets

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.

Best Answer

fid = fopen('file');
line1 = fgetl(fid);
res=line1;
while ischar(line1)
line1 = fgetl(fid);
res =char(res,line1)
end
fclose(fid);