How to plot in 3D a given set of data

Hello, so I have made a matrix with 3 columns. The first two are the x and y location of a point on a plate and the third is the wind speed at it. The matrix name is 'SPEED' and i want to plot it in 3D, as well as create a heatmap. Any ideas?
The ranges are the following. (Note: i can decrease the step as much as i like and make the curve as smooth as possible. I can gain the value of speed at any point using a given function. Just chose these steps so i do not tire my laptop)
x=[0:700:10800];
y=[0:770:11000];
Thank you

 Accepted Answer

I would do something like this —
x=[0:700:10800];
y=[0:770:11000];
[Xm,Ym] = ndgrid(x, y);
Zm = griddata(x, y, z, Xm, Ym);
figure
surf(Xm, Ym, Zm)
grid on
The heatmap only requires x-data and y-data. I am not certain how to use it with z-data as well. Consider using the countourf function instead.

6 Comments

hey, but how can i add z. Could you help me? I tried to define
z = SPEED(:,3)
but that doesnt seem to be working
Imagine I have just a table of values. Specific values. For specific x and y I have the z. How can i plot that
I am not entirely certain what you are describing, however this variation will likely work in that situation —
x = ...;
y = ...;
z = ...;
xv = linspace(min(x), max(x), numel(x));
yv = linspace(min(y), max(y), numel(y));
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x, y, z, Xm, Ym);
figure
surf(Xm, Ym, Zm)
grid on
For example —
x = randn(1,10);
y = randn(1,10);
z = randn(1,10);
xv = linspace(min(x), max(x), numel(x));
yv = linspace(min(y), max(y), numel(y));
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x, y, z, Xm, Ym);
figure
surf(Xm, Ym, Zm)
grid on
.
Hello, this is very helpful, but I still have errors when defining z. Imagine I have a table of values.
x=0 y=0 then z=15
x=1 y=0 then z=10
x=0 y=1 then z=12
x=2 y=0 then z=13
etc....
I mean, i have the values of z for a specific point (x,y) but i cannot define any function for z, i just have the ready calculated values for z. How can i plot that? What should i put in the code you described above in the z=....; part
Eventually I figured it all out. You have to define a matrix Z of [length(y),lentgth(x)] size with the resulting values
‘I mean, i have the values of z for a specific point (x,y) but i cannot define any function for z, i just have the ready calculated values for z. How can i plot that?
My code describes exactly that situation, and creates the matrices and the plot for them. It should do what you want. If there are specific problems with my code and your data, please share the data.
Eventually I figured it all out. You have to define a matrix Z of [length(y),lentgth(x)] size with the resulting values
I believe my code does exactly that.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!