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

1 次查看(过去 30 天)
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);

采纳的回答

KSSV
KSSV 2020-5-19
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by