필터 지우기
필터 지우기

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));

답변 (1개)

Steven Lord
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)
  댓글 수: 1
Syed Shahed
Syed Shahed 2020년 5월 1일
편집: Syed Shahed 2020년 5월 1일
Thank you for replying . But i want single quotes rather than double ones like '1' like character.
I want to do the operation like this along a whole matrix .
x=2.2
num2string(x)
ans= '2.2'
Can i do that? is it possible ?
Actually i want to convert the x=[1.25 2.2;3.5 6.2] matrix into a character matrix (array) like y=['1.25' '2.2';'3.5' '6.2]. Then i want to define the max decimal points that the character has among all the character.
How would i do that ? Any idea please

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by