필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Where is the problem

조회 수: 2 (최근 30일)
john
john 2012년 6월 4일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi, I got this error:
In an assignment A(:) = B, the number of elements in A and B must be the same.
UserData.info(4,2)=num2cell(sym(strcat('u',sym(UserData.matrix{4,2}))));
UserData.info and UserData.matrix are cell type.
I don't understand, where is problem?
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 6월 5일
I don't know what it would mean to strcat a string and a symbol. Unfortunately I do not have the toolbox to test with.

답변 (1개)

per isakson
per isakson 2012년 6월 5일
Try
UserData.info{ 4, 2 } =num2cell(sym(strcat('u',sym(UserData.matrix{4,2}))));
--- next ---
It is easier to debug and understand with one step per line:
temp1 = UserData.matrix{4,2};
temp2 = sym(temp1);
temp3 = strcat( 'u', temp2 );
temp4 = sym( temp3 );
temp5 = num2cell( temp4 );
UserData.info{ 4, 2 } = temp5;
whos temp*
.
--- next 2 ---
Is strcat supposed to concatenate a character, 'u' and something of class sym? What is this strcat-line supposed to do?
.
--- next 3 ---
Run this function and note that strcat fails when temp2 == 10. '10' is displayed on screen before the error message.
function cssm
temp1 = UserData.matrix{4,2};
for temp1 = 3 : 23
temp2 = sym(temp1);
try
temp3 = strcat( 'u', temp2 );
catch me
disp( temp2 )
rethrow( me )
end
temp4 = sym( temp3 );
temp5 = num2cell( temp4 );
UserData.info{ 4, 2 } = temp5;
end
whos temp*
end
>> cssm
10
In an assignment A(:) = B, the number of elements in A and B
must be the same.
Error in strcat (line 95)
s(pos:pos+len-1) = str;
Error in cssm (line 7)
temp3 = strcat( 'u', temp2 );
>>
The reason is that length( temp2 ) always returns 1. Thus, it works for one digit numbers, but not for 10 or 23.
My conclusions are:
  1. the function, strcat, is made for strings only
  2. all the numerical stuff in Matlab isn't tested with sym class input. At Mathworks they didn't anticipate that someone would through sym at strcat :-).
  댓글 수: 11
john
john 2012년 6월 5일
great......it works ....UserData.info{ 4, 2 } =num2cell(sym(strcat('u',char(sym(UserData.matrix{4,2})))));
big thank you ..
.
.
you help me a lot of time, how can I thank you?
Walter Roberson
Walter Roberson 2012년 6월 5일
All those sym() conversions give the impression that you are converting back and forth more often than you need to.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by