Assign number to symbol in cell array
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I want to assign a number (ex. 2) to a symbolic variable (x) in a cell array (A) using a cell array index operator {}.
syms x y ... ; A{1}=x; A{2}=y; ...
For example, if I write A{1}=2, then A{1} changes to 2; x does not become 2, definitely. Is there any way?
0 comentarios
Respuestas (1)
Abhiram Bhanuprakash
el 29 de Sept. de 2014
The behaviour which you have pointed out is expected, because you are setting the value of the cell array element A{1} to 2, but not setting a value to the symbol. Assigning a 'double' value to a 'sym' variable would just convert the 'sym' variable to a 'double'.
You can use the function SUBS to substitute a symbolic variable with a 'double' in MATLAB.
Here is some sample code to do the same:
>> syms x,y;
>> A{1} = x; A{2} = y;
>> subs(A{1}+A{2},A{1},5);
You would get the result to be
y + 5
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!