How to dynamically create symbolic variables?

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

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 13 de Feb. de 2014
Editada: Azzi Abdelmalek el 13 de Feb. de 2014
Edit
index = {'1'};
List = {'A','B','C'};
Temp=strcat(List,index)
A=sym(Temp)

3 comentarios

Kevin Bachovchin
Kevin Bachovchin el 13 de Feb. de 2014
A=sym('A', [1 10]) creates a vector of syms 'A1','A2','A3',...
Is there a way I can create 'A1','B1','C1' using a similar syntax?
Azzi Abdelmalek
Azzi Abdelmalek el 13 de Feb. de 2014
Editada: Azzi Abdelmalek el 13 de Feb. de 2014
index = {'1'};
List = {'A','B','C'};
Temp=strcat(List,index)
A=sym(Temp)
Kevin Bachovchin
Kevin Bachovchin el 13 de Feb. de 2014
Is there a way to ensure that the symbolic variables are real?

Iniciar sesión para comentar.

Más respuestas (2)

Roberto Germanà
Roberto Germanà el 15 de Feb. de 2017
Hello, can I create a matrx in the same way? e.g.
D = [D_11 D12
D_21 D_22]

1 comentario

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.

Iniciar sesión para comentar.

arpit patel
arpit patel el 26 de Mzo. de 2018

0 votos

for i=1:2 for j=1:2 D(i,j)=sym(['D_' num2str(i) num2str(j)]) end end

Preguntada:

el 13 de Feb. de 2014

Comentada:

el 26 de Mzo. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by