How do I plot a 3D surface where I have arrays x and y of same length and z values for each x and y value.

5 views (last 30 days)
So my code looks like the following
for n = 1:640; %number of time steps
for q = 1:640; %number of axial increments on a tool
Find a certain force f(q) = ...; % find force for each q increment
K = 100
z(n,q) = f(q)/K;
end
end
Now at the end I want to generate a surface where there is a z value for every q and every n combination. So z is a (n x q) size matrix. So I want 640 time steps as x. 640 axial increments as y, and a z value for each x and y combination. So the z matrix has 640*640 size

Answers (1)

Cris LaPierre
Cris LaPierre on 7 Dec 2018
Read the documentation for surf.
  5 Comments
Mirwais Sharifi
Mirwais Sharifi on 8 Dec 2018
That is not the complete code as the code is 200 lines. That is just the general logic behind what Im trying to do.
I have deleted the meshgrid and used the surf outside both for loops and get the error as data dimensions must agree.
So just to clarify what I'm trying to do:
I have 640 time increments (for n =1:640)
within each time increment I have 640 axial increments ( q = 1:640)
Now for each time increment and each of the 640 increments for the single increment I have a z value. z is (n x q) sized.
Fininally for each time increment ill have 640 z values. And same for next time increment (640 z values) until 640 time increments have completed and I'll have a total of 640x640 z values.
I am trying to plot the z values found for the corresponding n and q values in the for loop.
The surf documentation does not explain how to do this and says that x,y,z have to be matrices of the same size and I have no idea of going about this.
Thanks for your help Cris
Cris LaPierre
Cris LaPierre on 8 Dec 2018
Edited: Cris LaPierre on 8 Dec 2018
The hypothetical code is creating variables with the correct size. What is the size of the variables created in your actual code? Put a breakpoint in at the surf command and see what the actual size of n, q and z are.
And to clarify, the documentation does not say that X, Y, and Z have to be matrices. X and Y can be matrices or vectors. Z in the only one that has to be a matrix. As a simple example, see below:
n=1:40;
q=1:60;
z = n'*q;
surf(n,q,z')
simpleSurf.png

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!