3D mesh plot
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I wrote this code in order to get a 3D mesh plot based on those x,y,t values. is there any way to confirm that the plot would look like this? or i need to just trust Matlab with it? (added the plot)
%given data
x = [0 10 20 30 0 10 20 0 10 20 30];
y = [0 0 0 0 15 15 15 15 30 30 30 30];
t = [20 22 25 23 22 27 30 25 19 20 18 22];
%grid for x and y
%use unique so each value will be used once
[X,Y] = meshgrid(unique(x), unique(y));
%turning t into the same size as X and Y
T = reshape(t,length(unique(y)),length(unique(x)));
%3D plot for the values
figure;
mesh(X,Y,T);
xlabel('X');
ylabel('Y');
zlabel('T');

0 commentaires
Réponses (1)
Star Strider
le 27 Fév 2023
The ‘x’ vector is missing a ‘30’ value (supplied here).
I get a different result when I plot those data —
x = [0 10 20 30 0 10 20 30 0 10 20 30];
y = [0 0 0 0 15 15 15 15 30 30 30 30];
t = [20 22 25 23 22 27 30 25 19 20 18 22];
% Q = [size(x); size(y); size(t)]
xv = linspace(min(x), max(x), numel(x));
yv = linspace(min(y), max(y), numel(y));
[X,Y] = meshgrid(xv,yv);
F = scatteredInterpolant(x(:),y(:),t(:)); % Use 'scatteredInterpolant'
T = F(X,Y);
figure
surfc(X, Y, T)
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('T')
[Uy,yix] = unique(y);
Rows = mean(diff(yix));
X = reshape(x,Rows,[]); % Using 'reshape'
Y = reshape(y,Rows,[]);
T = reshape(t,Rows,[]);
figure
surfc(X, Y, T) % 'surfc'
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('T')
figure
meshc(X, Y, T) % 'meshc'
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('T')
Experiment to get different results.
.
0 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


