Assign number to symbol in cell array

조회 수: 3 (최근 30일)
Jongwook
Jongwook 2014년 9월 20일
답변: Abhiram Bhanuprakash 2014년 9월 29일
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?

답변 (1개)

Abhiram Bhanuprakash
Abhiram Bhanuprakash 2014년 9월 29일
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

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by