2d Surface Plot showing four outputs
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 25 de Jun. de 2015
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 comentarios
Walter Roberson
el 29 de Jun. de 2015
Editada: Walter Roberson
el 29 de Jun. de 2015
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.
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
