필터 지우기
필터 지우기

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