MATLAB: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

I'm trying to read a matrix from file, but my code works only if matrix is 3*3. So, if I make it smaller or bigger, this error occurs. I am new to MATLAB. Help me please to solve my problem
Here's my code:
fid = fopen ('Matrix_A.txt','r');
i = 1;
while ~feof(fid)
A(i, :) = str2num(fgets(fid));
i = i + 1;
end
fclose(fid);

Best Answer

fid = fopen ('Matrix_A.txt','r');
i = 1;
A = cell([],1) ;
while ~feof(fid)
A{i} = str2num(fgets(fid));
i = i + 1;
end
fclose(fid);
You can access A by using flower braces, A is a cell. A{1}, A{2}, .....etc.