MATLAB 3D Plotting: Tutorial & Help

  • Context: MATLAB 
  • Thread starter Thread starter elham
  • Start date Start date
  • Tags Tags
    3d Matlab Plotting
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
elham
Messages
1
Reaction score
0
Hi Friends,
The code below is for 2D ploting in Matlab, I want to change it in 3D, please if anyone know how to do this.let me know
thanks in advancefigure(1);
popcosts=[pop.Cost];
repcosts=[rep.Cost];
plot(popcosts(1,:),popcosts(2,:),'b.');
hold on;
plot(repcosts(1,:),repcosts(2,:),'r*');
hold off;
legend('Normal Particles','Repository Particles');
xlabel('f_1');
ylabel('f_2');
 
Last edited by a moderator:
Physics news on Phys.org
What is your z variable? You need a third variable of values to plot in 3D.

For example,

surf(popcosts(1,:),popcosts(2,:),popcosts(3,:))

You could also use surfc, contour, plot3, and countless other functions for 3D plotting. Answer the below questions, and then click the following link:

http://www.mathworks.com/help/matlab/2-and-3d-plots.html

1. What kind of plot do you want?
2. What are your 3 variables?