Contourf and Surf with repeated values
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lorenzo Pasinato
el 16 de Dic. de 2022
Respondida: Fabio Freschi
el 16 de Dic. de 2022
If I have a matrix (or a .mat file) like in screenshot, so with same ordered values, how can I do plot the third column as Z? The problem is that i can't give the first column as X and the second as Y.
Thank you!
0 comentarios
Respuesta aceptada
Fabio Freschi
el 16 de Dic. de 2022
Suppose you have Nx divisions along the variable of the first column and Ny divisions along the variable of the second column. You must reshape the columns of your matrix according to Nx and Ny
clear variables, close all
Nx = 5;
Ny = 6;
% create your matrix with random inputs
x = linspace(0,1,Nx);
y = linspace(1,2,Ny);
[X0,Y0] = meshgrid(x,y);
Z0 = X0.^2-3*X0.*Y0;
M = [X0(:) Y0(:) Z0(:)];
% The engine you want starts here -----
% reshape the columns of the matrix
X = reshape(M(:,1),Ny,Nx);
Y = reshape(M(:,2),Ny,Nx);
Z = reshape(M(:,3),Ny,Nx);
% plot
figure
surf(X,Y,Z);
view([1 1 1])
Hope it helps!
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!