Unable to perform assignment because the indices on the left side are not compatible with the size of the right side
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am confused yet . I hoped to get string (i dont know what i have to say character or string) values for every matrix elements but i didnt happen.
Example- Input=[1.25 2.2;3.5 6.2] and Output=['1.25' '2.2';'3.5' '6.2]
Can anyone explain me please, whats the error inside the code ?
%Code
function y=elementsnumber2string(x)
[m,n]=size(x);
y=[];
for i=1:m
for j=1:n
y(i,j)=num2str(x(i,j));
end
end
end
%Output
Unable to perform assignment because
the indices on the left side are not
compatible with the size of the right
side.
Error in findafterdecimalponts (line
6)
y(i,j)=num2str(x(i,j));
2 Kommentare
Antworten (1)
Steven Lord
am 1 Mai 2020
y(i, j) refers to exactly one element of y as you've defined i and j. How many elements does, say, '10' have?
numel(num2str(10))
You can't fit two characters into a space big enough to hold one.
Depending on which release you're using and how you want to use y, what you're trying to do could be as simple as calling string on the matrix x.
x = magic(5)
y = string(x)
y(2, 4)
1 Kommentar
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!