How to ensure that dynamically create symbolically variables are real?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hello,
I'm creating symbolic variables dynamically and I wanted to ensure that the symbolic variables are real.
I have the code
clear all
index = {'1'};
List = {'A','B','C'};
A=sym(strcat(List,index))
How can I modify this to make sure that the symbolic variables stored in A are real? I have tried changing to A=sym(strcat(List,index),'real'), but this doesn't work.
Thank you, Kevin
1 Comment
Kevin Bachovchin
on 14 Feb 2014
Edited: Kevin Bachovchin
on 14 Feb 2014
Answers (2)
Azzi Abdelmalek
on 14 Feb 2014
I don't think you can, for example force the variable A1 to be real. If
A1=5+j
Then
index = {'1'};
List = {'A','B','C'};
A=sym(strcat(List,index))
out=subs(A(1))
The result is a complex number
5 Comments
Kevin Bachovchin
on 14 Feb 2014
Edited: Kevin Bachovchin
on 14 Feb 2014
Azzi Abdelmalek
on 14 Feb 2014
n=3
a=sprintf('A%d ',1:n)
eval(['syms ' a ' real'])
eval(['A=[' a ']'])
Kevin Bachovchin
on 14 Feb 2014
Azzi Abdelmalek
on 14 Feb 2014
s=regexp('A':'Z','.','match')
n=3
a=strjoin(strcat(s(1:n),'1'))
eval(['syms ' a ' real'])
eval(['A=[' a ']'])
Kevin Bachovchin
on 14 Feb 2014
Kevin Bachovchin
on 20 Feb 2014
2 Comments
Walter Roberson
on 21 Feb 2014
Not if the variable names are not all the same number of characters.
Kevin Bachovchin
on 21 Feb 2014
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!