Clear Filters
Clear Filters

Converting cell vector to symbolic vector

1 view (last 30 days)
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 !

Accepted Answer

Kim O
Kim O on 17 May 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 Comment
Walter Roberson
Walter Roberson on 17 May 2012
I think that should be sym(x_str{i}) with {} instead of ()

Sign in to comment.

More Answers (1)

Kim O
Kim O on 17 May 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 Comments
Kim O
Kim O on 19 May 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]

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!