Unable to perform assignment because the indices on the left side are not compatible with the size of the right side
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Steven Lord
2020년 5월 1일
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)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!