Surf plot of minimum values of four matrices

2 visualizaciones (últimos 30 días)
Gaetano Pavone
Gaetano Pavone el 22 de Mzo. de 2023
Editada: DGM el 22 de Mzo. de 2023
Hello, I have the following 4 matrices:
ZCV=[1 2 1 2;6 5 2 8;3 5 9 4; 11 2 0.5 6]; % yellow surf
ZBTmod=[5 2 9 4;1 2 0.2 9;10 9 5 7; 0.6 5 8.3 4]; % cyan surf
ZCD=[2 8 9 5;1 0.2 5 8;6 2 5 8; 0.6 9 8 7]; % red surf
ZCB=[6 2 6 2;2.3 6 7.3 5;4 4 4 6; 0.1 2 8 6]; % blue surf
I would like to plot a surf of minimum values of these 4 matrices with view (0 90) such that the color of a portion of the surf is consistent with the color indicated above. Attached is a sketch of my idea:

Respuesta aceptada

DGM
DGM el 22 de Mzo. de 2023
Editada: DGM el 22 de Mzo. de 2023
I don't know how you intend to get that plot from that data, but maybe your actual data has more resolution.
ZCV=[1 2 1 2;6 5 2 8;3 5 9 4; 11 2 0.5 6]; % yellow surf
ZBTmod=[5 2 9 4;1 2 0.2 9;10 9 5 7; 0.6 5 8.3 4]; % cyan surf
ZCD=[2 8 9 5;1 0.2 5 8;6 2 5 8; 0.6 9 8 7]; % red surf
ZCB=[6 2 6 2;2.3 6 7.3 5;4 4 4 6; 0.1 2 8 6]; % blue surf
% stack the arrays
ZZ = cat(3,ZCV,ZBTmod,ZCD,ZCB);
% find the minimum values and the corresponding source index
[Z idx] = min(ZZ,[],3);
% if all that's desired is a flat-colored image
% then there's no need for surf() or the Z data
% just generate an image from the indices and the colormap
CT = [1 1 0;
0 1 1;
1 0 0;
0 0 1];
outpict = ind2rgb(idx,CT);
% image has the same size as the Z data
imshow(outpict)
  3 comentarios
Gaetano Pavone
Gaetano Pavone el 22 de Mzo. de 2023
I used this modified version of your code:
ZZ = cat(3,ZCV,ZBTmod,ZCD,ZCB);
[Z,idx] = min(ZZ,[],3);
lengthCV=[1:9];
[X,Y] =meshgrid(3:20,lengthCV);
surf(X,Y,idx)
view(axes1,[0 90]);
This is the result:
I want to assign the color matrix according to the previous color's definition. How can I do this?
Gaetano Pavone
Gaetano Pavone el 22 de Mzo. de 2023
I solved by adding:
CT = [1 1 0;
0 1 1;
1 0 0;
0 0 1];
colormap(CT)
However the legend is not consistent with the colors. How can I fix it?

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 22 de Mzo. de 2023
Create the four surfaces.
ZCV=[1 2 1 2;6 5 2 8;3 5 9 4; 11 2 0.5 6]; % yellow surf
surf(ZCV, FaceColor = "y")
hold on
ZBTmod=[5 2 9 4;1 2 0.2 9;10 9 5 7; 0.6 5 8.3 4]; % cyan surf
surf(ZBTmod, FaceColor = "c")
ZCD=[2 8 9 5;1 0.2 5 8;6 2 5 8; 0.6 9 8 7]; % red surf
surf(ZCD, FaceColor = "r")
ZCB=[6 2 6 2;2.3 6 7.3 5;4 4 4 6; 0.1 2 8 6]; % blue surf
surf(ZCB, FaceColor = "b")
Look at the axes from below.
view([0 0 -1]) % or view(0, -90)
  2 comentarios
Gaetano Pavone
Gaetano Pavone el 22 de Mzo. de 2023
Your solution is simpler but the y-axis is inverted
DGM
DGM el 22 de Mzo. de 2023
Editada: DGM el 22 de Mzo. de 2023
You can just do
set(gca,'ydir','reverse')
If my answer wasn't what you wanted, you can always change which answer you accept.

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by