represent symbolic toolbox as a string
Afficher commentaires plus anciens
I am using the symbolic toolbox in Array1. How do you represent it as a string?
syms r,theta,phi
x=r*cos(theta)*cos(phi)
y=r*sin(theta)*cos(phi)
z=r*sin(phi)
Array1=num2str([x y z])
Réponses (1)
sixwwwwww
le 6 Déc 2013
try this:
syms r theta phi
x=r*cos(theta)*cos(phi)
y=r*sin(theta)*cos(phi)
z=r*sin(phi)
Array1 = char([x y z])
5 commentaires
Philosophaie
le 6 Déc 2013
sixwwwwww
le 6 Déc 2013
if you want to extract string from array then it will be better to save the string in cell array as follow:
syms r theta phi
x = r * cos(theta) * cos(phi);
y = r * sin(theta) * cos(phi);
z = r * sin(phi);
Array1 = {char(x), char(y), char(z)};
Now you can extract all three string as follow:
Array1{1} % 1st string
Array1{2} % 2nd string
Array1{3} % 3rd string
Philosophaie
le 6 Déc 2013
Modifié(e) : Philosophaie
le 6 Déc 2013
sixwwwwww
le 6 Déc 2013
you can do it as follow:
syms r theta phi
x = r * cos(theta) * cos(phi);
y = r * sin(theta) * cos(phi);
z = r * sin(phi);
Array1 = {char(x), char(y), char(z)};
% Print string on command window
for i = 1:3
fprintf('String number %d is: %s\n', i, Array1{i})
end
Walter Roberson
le 11 Déc 2013
Change
Array2(n)=char(Array1(i,j,k,l))
to
Array2{n}=char(Array1(i,j,k,l))
Catégories
En savoir plus sur Conversion Between Symbolic and Numeric dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!