Surf plot of minimum values of four matrices

2 次查看(过去 30 天)
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:

采纳的回答

DGM
DGM 2023-3-22
编辑:DGM 2023-3-22
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 个评论
Gaetano Pavone
Gaetano Pavone 2023-3-22
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 2023-3-22
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?

请先登录,再进行评论。

更多回答(1 个)

Steven Lord
Steven Lord 2023-3-22
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 个评论
Gaetano Pavone
Gaetano Pavone 2023-3-22
Your solution is simpler but the y-axis is inverted
DGM
DGM 2023-3-22
编辑:DGM 2023-3-22
You can just do
set(gca,'ydir','reverse')
If my answer wasn't what you wanted, you can always change which answer you accept.

请先登录,再进行评论。

类别

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

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by