2d Surface Plot showing four outputs

조회 수: 2 (최근 30일)
Abbas Ihsan
Abbas Ihsan 2015년 6월 25일
댓글: Abbas Ihsan 2015년 6월 29일
Hi, I'll appreciate if anyone could guide me in this. I want a 2d surface plot to show four different outputs that are changing for each x and y values. For example:
x y output1 output2 output3 output4
0.0200 5.5000 0.4720 0.3403 0.0997 0.0880
0.0200 6.0000 0.4662 0.3431 0.1001 0.0906
I want to show the outputs (1-4) each with a different color while the color increases or decreases as the output changes..??

답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 25일
If your x and y form a rectangular grid,
datamin = min( [min(output1(:)), min(output2(:)), min(output3(:)), min(output4(:))] );
datamax = max( [max(output1(:)), max(output2(:)), max(output3(:)), max(output4(:))] );
datarange = ceiling(datamax - datamin);
color1 = (output1 - datamin) / datarange / 4;
surf(x, y, output1, color1);
caxis([0 1]);
hold on;
color2 = (output2 - datamin) / datarange / 4 + 1/4;
surf(x, y, output2, color2);
color3 = (output3 - datamin) / datarange / 4 + 1/2;
surf(x, y, output3, color3);
color4 = (output4 - datamin) / datarange / 4 + 3/4;
surf(x, y, output4, color4);
This normalized the data into equally-spaced bands relative to the minimum and maximum data values (so this code will work even if the values are negative), with the first output occupying 0 to 1/4 in the color information, the second occupying 1/4 to 1/2, and so on. The maximum output color information here is 1. These values will be scaled to the number of entries in your colormap in order to determine the color to use.
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 6월 29일
편집: Walter Roberson 2015년 6월 29일
datarange = ceil(datamax - datamin);
The formal name of the operation is "ceiling" but MATLAB calls it "ceil".
Basically ceil() rounds up to the nearest integer. You do not need to do the rounding up; you could use
datarange = datamax - datamin;
I put the ceil() part in to make the ranges "prettier" and to make the plots a little less sensitive to the exact data values, so that if the next plot of the same type happened to have slightly larger ranges of data that the plot would often still come out the same.
Abbas Ihsan
Abbas Ihsan 2015년 6월 29일
I got it working but the issue remains. I get 4 different surfaces for my 4 outputs in one surface plot but in the x-y view (2D view) it isn't showing all the outputs. The figure shows the 3D and and its 2D.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by