Where is the problem

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 comentario

Walter Roberson
Walter Roberson el 5 de Jun. de 2012
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.

Respuestas (1)

per isakson
per isakson el 5 de Jun. de 2012

1 voto

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 comentarios

john
john el 5 de Jun. de 2012
Sorry,, but this code doesn't work :-(
Oleg Komarov
Oleg Komarov el 5 de Jun. de 2012
Saying it doesn't work really doesn't help to understand what's going on. Be more specific, and post any error message you get.
john
john el 5 de Jun. de 2012
this is the error message:
??? In an assignment A(:) = B, the number of elements in A and B
must be the same.
Error in ==> strcat at 96
s(pos:pos+len-1) = str;
Error in ==> menu>pushbutton12_Callback at 2563
UserData.info{ 4, 2 } =num2cell(sym(strcat('u',sym(UserData.matrix{4,2}))));
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> menu at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)menu('pushbutton12_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
john
john el 5 de Jun. de 2012
if UserData.matrix{4,2} is only one number like 5, then it is ok, but if UserData.matrix{4,2} is bigger number like 23, then I got error message
Walter Roberson
Walter Roberson el 5 de Jun. de 2012
When UserData.matrix{4,2} is a larger number like 23, then try
T1 = sym(UserData.matrix{4,2});
class(T1), size(T1)
T2 = strcat('u', T1);
class(T2), size(T2)
I have suspicions, but I do not have any way to test them myself.
john
john el 5 de Jun. de 2012
Walter, if UserData.matrix{4,2} is like 3, then class(T1)=sym, and size(T1)=1,1 ; and all is OK
;
;
but if UserData.matrix{4,2} is like 34, then also class(T1)=sym, and size(T1)=1,1, ;, but from T2 = strcat('u', T1); I got error
john
john el 5 de Jun. de 2012
problem is command sym.......T1 = sym(UserData.matrix{4,2});,,,,,,strcat has problem with sym,
,
,
,
easy example ......try strcat('d',sym('4')) and strcat('d',sym('45'))
Walter Roberson
Walter Roberson el 5 de Jun. de 2012
So perhaps it should be
UserData.info{ 4, 2 } =num2cell(sym(strcat('u',char(sym(UserData.matrix{4,2})))));
Question: what data types are likely to occur in the UserData.matrix elements that you would use?
john
john el 5 de Jun. de 2012
into UserData.matrix I write by thes way: UserData.matrix(4,4)=num2cell(sym(get(handles.edit7,'string')));
john
john el 5 de Jun. de 2012
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 el 5 de Jun. de 2012
All those sym() conversions give the impression that you are converting back and forth more often than you need to.

La pregunta está cerrada.

Etiquetas

Preguntada:

el 4 de Jun. de 2012

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by