フィルターのクリア

Converting cell vector to symbolic vector

1 回表示 (過去 30 日間)
Kim O
Kim O 2012 年 5 月 17 日
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 !

採用された回答

Kim O
Kim O 2012 年 5 月 17 日
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 件のコメント
Walter Roberson
Walter Roberson 2012 年 5 月 17 日
I think that should be sym(x_str{i}) with {} instead of ()

サインインしてコメントする。

その他の回答 (1 件)

Kim O
Kim O 2012 年 5 月 17 日
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 件のコメント
Walter Roberson
Walter Roberson 2012 年 5 月 17 日
subs(x_sym)
Kim O
Kim O 2012 年 5 月 19 日
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]

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by