Representing data as surface

7 次查看(过去 30 天)
Kaouthar Kaouthar
Hello, I am trying to plot a surface from my data (x,y,z). I have a collection of data with the following (X, Y, Z) triplets:
Capture.JPG
I have represented x, y and z in the form of matrix (as shown in my code below) and I have tried to represent the values of z with respect to x and y and that s what i have found as result:
jkj.JPG
The result is not correct, I wanted to have the 25 values of z represented each one in a specific color.
for example for x=1 and y=25, i want to have a colored surface that represent z= 0.192678 and the same thing for all the others.
(with stem3, it s ok, i have my 25 vertices but i want to obtain 25 colored surfaces)
This is my code and data:
close all
clear all
x=[1 1.02 1.06 1.08 1.1 ;1 1.02 1.06 1.08 1.1; 1 1.02 1.06 1.08 1.1;1 1.02 1.06 1.08 1.1;1 1.02 1.06 1.08 1.1];
y=[25 25 25 25 25; 28 28 28 28 28; 30 30 30 30 30; 35 35 35 35 35; 40 40 40 40 40];
z=[0.1926782273603 25.7666609559705 26.3758732322372 17.0874435713091 2.61780104712041;...
0.50550640909912 25.1708618103017 33.1627906976744 7.59717314487632 0.342836521111504 ;...
1.23900161608907 25.8307914593033 41.9949352841868 32.1646341463415 4.74541046068583 ;...
0.274630964641264 25.831399845321 49.0575458744227 20.4442361761949 22.8672566371681 ;...
2 28.1091559797196 33.3518005540166 18.3106367316894 24.7384937238494 ];
figure
% stem3(x,y,z)
surf(x,y,z)
% shading flat
colormap jet
Any help would be strongly appreciated.
Thank you in advance

回答(1 个)

Star Strider
Star Strider 2019-8-3
See if adding
view(20, 20)
after your surf call does what you want.
  4 个评论
Kaouthar Kaouthar
I want to represent the corresponding z of each couple (x,y) by a surface in order to obtain a map containing the 25 values of z represented by surfaces at the end.
I strated by this link,(https://fr.mathworks.com/help/matlab/visualize/representing-a-matrix-as-a-surface.html) it gives how to plot what i want but with vertices (reshaping data in the link)
I want the same thing but with surfaces not vertices.
Thank you again!
Star Strider
Star Strider 2019-8-3
My pleasure.
THe surf plot creates a surface, so it does what you say you want.
I have no idea what you want, so:
Try this:
figure
surf(x,y,z)
view(20, 20)
shading('interp')
colormap jet
or this:
[X,Y] = meshgrid(1:0.01:1.1, 25:0.25:40);
Z = griddata(x, y, z, X, Y, 'cubic');
figure
surf(X, Y, Z)
view(20, 20)
shading('interp')
colormap jet
to see if those are what you want. Note that the second just interpolates to a finer grid, and uses a cubic interpolation function.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by