Storing variable from a loop

1 view (last 30 days)
Luv
Luv on 12 Jul 2013
Hi I have the following program:
N=1;
for i=1:N+1;
for j=1:N+1;
for k=1:N+1;
T=[0 0 0 (i-1)/N; 0 0 0 (j-1)/N; 0 0 0 (k-1)/N]);
A = T(:,4)'; % Notice the transpose
x= A(:,1);
y= A(:,2);
z= A(:,3);
scatter3(x,y,z,'filled');
hold all;
end
end
end
% from the T matrix, I want to extract my x, y and z coordinates where x=T(1,4), Y=T(2,4), Z=T(3,4).
there will be 8 possible combinations. Using those coordinates I want to create a surface. I have been able to individually extract the values of the coordinates but the program overwrites the value each time the loop runs. I am using x= A(:,1); etc. This way I am able to plot all 8 points but cannot make a surface.

Answers (1)

Matt J
Matt J on 12 Jul 2013
[x,y,z]=meshgrid((0:N)/N);
scatter3(x(:),y(:),z(:));
  2 Comments
Luv
Luv on 12 Jul 2013
Hi Matt,
I want to make a surface plot that spans these points.
The function that you provided does not change my plot in any way although it does alter the way that I store my matrix.
Thank you for your input.
Matt J
Matt J on 12 Jul 2013
You can do
surf(x,y,z)
for a surface plot using the same data.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!