MATLAB: Storing while loop values in a vector?? Error

MATLABvectorwhile loop

fid = fopen('example.txt');
sample=[]; %empty matrix count=1;
tline=fgetl(fid); while ischar(tline) disp(tline) sample(count)=tline; count=count+1; tline=fgetl(fid); end
fclose(fid);
I am trying to run this while loop and save each value consecutively in the vector "sample". "sample" should end with one column and an unknown amount of rows of strings.
I am getting the error 'Subscripted assignment dimension mismatch.' Is it because I'm starting with an empty vector?? Is it because each row is a string?? Please help.

Best Answer

It might be easier here to use a cell array as such
fid = fopen('example.txt');
sample={}; %empty matrix count=1;
j = 1
tline=fgetl(fid);
while ischar(tline)
disp(tline);
sample{j} = tline
tline=fgetl(fid);
j = j+1
end
fclose(fid);