Converting cell vector to symbolic vector

2 visualizaciones (últimos 30 días)
Kim O
Kim O el 17 de Mayo de 2012
Hello,
I am a beginner in Matlab so I hope you can help me:
I have a vector (Class:cell) e.g. x=[x_a ; x_b ; y_a]; I need a conversion to symbolic vector, because I need a Matrix Vector operation, e.g. b=A*x
I hope there is a solution for this kind of problem.
Thank you !

Respuesta aceptada

Kim O
Kim O el 17 de Mayo de 2012
fid = fopen('x.txt');
x_str1 = textscan(fid, '%s');
fclose(fid);
x_str=x_str1{1};
diim=size(x_str,1);
for i=1:diim
xs(i,1)= sym(x_str(i));
end
  1 comentario
Walter Roberson
Walter Roberson el 17 de Mayo de 2012
I think that should be sym(x_str{i}) with {} instead of ()

Iniciar sesión para comentar.

Más respuestas (1)

Kim O
Kim O el 17 de Mayo de 2012
it doesnt work because if my cell vector ist x_cell=[sin(t) ; t] and i convert this as shown above i get x_sym=[sin(t) ; t]
BUT: If I define t=sym('t'); and then t=pi; ==> x_sym is NOT [sin(pi) ; pi] Has anyone a SOLUTION?
  2 comentarios
Walter Roberson
Walter Roberson el 17 de Mayo de 2012
subs(x_sym)
Kim O
Kim O el 19 de Mayo de 2012
Thats great, thank you Walter, it works!
But lets say I have a symbolic x=[U1 ; U2];
And my symbolic xs that I generate from my txt file is xs=[x(1)+2 ; x(1)+x(2)];
with subs(xs) I don't get xs=[U1+2 ; U1+U2]

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by