2d Surface Plot showing four outputs
조회 수: 2 (최근 30일)
이전 댓글 표시
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..??
댓글 수: 0
답변 (1개)
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
