how to color the difference between two variables specifing the colors

1 次查看(过去 30 天)
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!

回答(1 个)

Image Analyst
Image Analyst 2015-12-24
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.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by