Assign number to symbol in cell array
조회 수: 12(최근 30일)
표시 이전 댓글
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
답변(1개)
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
댓글 수: 0
참고 항목
범주
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!