Borrar filtros
Borrar filtros

how to color the difference between two variables specifing the colors

1 visualización (últimos 30 días)
Michela
Michela el 24 de Dic. de 2015
Respondida: Image Analyst el 24 de Dic. de 2015
Hello, I am a beginner user of this very useful (but, for me, weird :-) ) software. As far, I have not so many problems, but now I need to create a figure in which I have two lines (one for each column of my matrix pM) and the area inside these lines has to be colored in red if the difference between the value of the two columns is negative, in blue otherwise. In other words, i=pM(:,1)-pM(:,2) if i<0 the area between pM(:,1) and pM(:,2) is red. How can I implement it in matlab???? Thank you!

Respuestas (1)

Image Analyst
Image Analyst el 24 de Dic. de 2015
Here's a start:
pM = rand(20, 2)
col1 = pM(:, 1);
col2 = pM(:, 2);
area(col1, 'FaceColor', 'b');
hold on;
area(col2, 'FaceColor', 'r');
legend('col1', 'col2');
minY = min([col1,col2], [], 2)
area(minY, 'FaceColor', 'w');
plot(col1, 'bo-', 'LineWidth', 2);
plot(col2, 'rd-', 'LineWidth', 2);
grid on;
If you want it to follow the slants, then you're going to have to increase the sampling so that you have data there.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by