how to store all values of a matrix variable during the loop

1 次查看(过去 30 天)
theta=-pi/6:pi/180:pi/6;
phi=-pi/6:pi/180:pi/6;
[theta,phi]=meshgrid(theta,phi);
for rho=5:.025:50
[x,y,z]=sph2cart(theta,phi,rho);
xs=min(x(:)):0.03:max(x(:))+1;
ys=min(y(:)):0.15:max(y(:))+1;
zs=min(z(:)):0.15:max(z(:))+1;
end
I want to store the overall x,y&z and xs,ys&zs

采纳的回答

Bob Thompson
Bob Thompson 2019-4-9
You need to add indexes to your outputs. Typically, it is usually appropriate to use your loop index value as the index, however, because your index is not always a real positive integer you will need to add some kind of counter into the loop.
c = 1;
for rho = 5:.025:50
[x(c),y(c),z(c)] =
xs(c) =
...
c = c + 1;
end
It may take some tweaking, but that's the basic idea.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by