How to dynamically create symbolic variables?

4 views (last 30 days)
Hello,
I'm looking for a way to dynamically create symbolic variables.
For example with the code,
clear all
index = '1';
List = ['A','B','C'];
for i = 1:numel(List)
Temp = [List(i) index]
end
Is there a way I can create symbolic variables with the string stored in Temp?
Thank you, Kevin

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 13 Feb 2014
Edited: Azzi Abdelmalek on 13 Feb 2014
Edit
index = {'1'};
List = {'A','B','C'};
Temp=strcat(List,index)
A=sym(Temp)
  3 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 13 Feb 2014
Edited: Azzi Abdelmalek on 13 Feb 2014
index = {'1'};
List = {'A','B','C'};
Temp=strcat(List,index)
A=sym(Temp)
Kevin Bachovchin
Kevin Bachovchin on 13 Feb 2014
Is there a way to ensure that the symbolic variables are real?

Sign in to comment.

More Answers (2)

Roberto Germanà
Roberto Germanà on 15 Feb 2017
Hello, can I create a matrx in the same way? e.g.
D = [D_11 D12
D_21 D_22]
  1 Comment
Walter Roberson
Walter Roberson on 26 Mar 2018
D = sym('D_%d%d',[2,2]);
D(1,2) = sym('D12') ;
I do not know why the one entry is not to follow the pattern, but here it is.

Sign in to comment.


arpit patel
arpit patel on 26 Mar 2018
for i=1:2 for j=1:2 D(i,j)=sym(['D_' num2str(i) num2str(j)]) end end

Community Treasure Hunt

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

Start Hunting!