Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
1 view (last 30 days)
Show older comments
Valeriia Okromelidze
on 19 May 2020
Edited: Valeriia Okromelidze
on 19 May 2020
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);
0 Comments
Accepted Answer
KSSV
on 19 May 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!