MATLAB Loops: Help Needed with Surface Plotting

In summary, The conversation is about someone asking for help with using MATLAB for loops to create a surface plot with two varying parameters. They are having trouble with getting the LHS of their statements correct and are looking for a helpful website to guide them.
  • #1
physicsCU
202
1
Hey guys,

Is there anyone good with MATLAB for loops? I am having trouble with getting an embedded loop within another loop to work.

I am trying to vary two parameters and create a surface plot with a third variable as the dependant.

What I really need help with is how to get the LHS of my statements correct. I will post my code later tonight, its on another computer, but if anyone has a good site to help me out in the mean time, that would be great.

Thanks!
 
Physics news on Phys.org
  • #2
Er, what error are you getting?
 
  • #3
Its not an error perse, its just that i get a line in 3d space, when i should be getting a surface plot, because two variables are being varied at all points.
 

1. What is a MATLAB loop?

A MATLAB loop is a programming structure that allows you to repeat a set of instructions multiple times. It iterates through a block of code until a certain condition is met or a certain number of iterations is reached.

2. How do I create a loop in MATLAB?

To create a loop in MATLAB, you can use the for or while loop structures. The for loop is used when you know the number of iterations beforehand, while the while loop is used when the number of iterations depends on a condition.

3. How can I use a loop for surface plotting in MATLAB?

To plot a surface using a loop in MATLAB, you can use the meshgrid function to create a grid of x and y coordinates, and then use a nested for loop to calculate the z coordinates for each point on the grid. Finally, you can use the surf function to plot the surface using the x, y, and z coordinates.

4. What are the benefits of using loops for surface plotting in MATLAB?

The main benefit of using loops for surface plotting in MATLAB is that it allows you to plot complex surfaces with varying or non-linear data. It also provides more control over the plotting process, as you can customize the number of iterations and the range of values for the x and y coordinates.

5. Are there any alternatives to using loops for surface plotting in MATLAB?

Yes, there are alternatives to using loops for surface plotting in MATLAB. One alternative is to use the surf function with vector inputs for x, y, and z. Another option is to use the plot3 function, which allows you to plot 3D data without using loops.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Back
Top