Converting 2x1 Symbolic array to 2x1 Numeric matrix in Matlab
Show older comments
I have a 2x1 symbolic array (2x1 sym):
C =
-(l1*(- l2*m2*sin(fi1 - fi2)*fidot2^2 + gr*m1*sin(fi1) + 2*gr*m2*sin(fi1)))/2
-(l2*m2*(l1*sin(fi1 - fi2)*fidot1^2 + gr*sin(fi2)))/2
here l1, l2, fi1, fi2, gr and etc. are symbolic variables.
I need to convert C symbolic array to 2x1 numeric matrix in a separate function tab in Matlab, where l1, l2, fi1, fi2 and etc. are given already.
I made a txt file with following commands:
smth=char(C);
fileID = fopen('C.txt','rt');
fprintf(fileID,'%s',smth);
fclose(fileID);
and it made a txt file with following content:
matrix([[-(l1*(gr*m1*sin(fi1) + 2*gr*m2*sin(fi1) -
fidot2^2*l2*m2*sin(fi1
- fi2)))/2], [-(l2*m2*(gr*sin(fi2) + fidot1^2*l1*sin(fi1 - fi2)))/2]])
But, I couldn't find a way to convert it back to numeric matrix.
What could be a way to convert symbolic matrix to numeric matrix?
1 Comment
madhan ravi
on 10 Feb 2019
See about subs().
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!