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
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 Comments
Answers (1)
Steven Lord
on 1 May 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)
See Also
Categories
Find more on Logical 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!