represent symbolic toolbox as a string

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])

Antworten (1)

sixwwwwww
sixwwwwww am 6 Dez. 2013

0 Stimmen

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 Kommentare

Is this how you write a string from Array1?
for i=1:4
for j=1:4
for k=1:4
string1(i,j,k) = 'Array1(' & i & ',' & j & ',' & k & ')' & char(Array1(i,j,k))
next
next
next
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
Philosophaie am 6 Dez. 2013
Bearbeitet: Philosophaie am 6 Dez. 2013
n=0;
for l=1:4
for k=1:4
for j=1:4
for i=1:4
n=n+1;
Array2(n)=char(Array1(i,j,k,l));
end
end
end
end
??? In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in ==> matlab at 57 Array2(n)=char(Array1(i,j,k,l));
How do I get a sequential printout of an array?
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
Change
Array2(n)=char(Array1(i,j,k,l))
to
Array2{n}=char(Array1(i,j,k,l))

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 6 Dez. 2013

Kommentiert:

am 11 Dez. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by