MATLAB: How to initialize an M×N array whose size is unknown in for-loop

array

Hi All,
I am trying to read 150 text files. Each contains the value of x and y. x is the input of an experiment and y is the measured value. Each experiment has different number of data. The number of data cannot be determined until I have read each file.
How should I use the arrays which store x and y in a for-loop efficiently to speed up the process of reading? How should I initialize them while each experiment has different number of elements? I tried to use a code similar to the following code.
x=zeros(??,150);
y=zeros(??,150);
for i=1:150
fid=fopen(fname);
data=textscan(fid,'%f %f');
x(??,i)=data{1}
y(??,i)=data{2}
end
By ?? I mean I don't exactly know what to use. Could someone please help me?
Thanks.

Best Answer

x = cell(150,1);
y = cell(150,1);
for K = 1 : 150
fid=fopen(fname);
data = textscan(fid, '%f %f');
x{K} = data{1};
y{K} = data{2};
end
You can always put them in to a matrix after you have collected them all. If you do that, you will need to decide how you want to pad the shorter columns.