Surf plot of minimum values of four matrices

조회 수: 2 (최근 30일)
Gaetano Pavone
Gaetano Pavone 2023년 3월 22일
편집: DGM 2023년 3월 22일
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