How can I plot coordinates with different colours based on the value and family of my variables ?

조회 수: 3 (최근 30일)
How can I associate a colour to a coordinate depending on the family of its highest associated value ?
For example, if my coordinates are X=[2 4 -3 5 6] and Y=[4 9 1 -2 1] and my associated values are L1 (blue) =[1 1 1 1 1], L2 (green) =[2 1 2 1 2], L3 (red) =[3 3 3 3 1] and L4 (purple) =[10 0 2 0 0], I want the coordinate (2,4) to be purple, the coordinate (4,9) to be red, the coordinate (-3 1) to be red and so on.
The main objective is to make a "phase diagram" that tell us which treatment between L1, L2, L3 and L4 is the most optimal (has the highest value) for each point in space.

채택된 답변

Simon
Simon 2013년 11월 15일
Hi!
X = [2 4 -3 5 6];
Y = [4 9 1 -2 1];
L1 = [1 1 1 1 1];
L2 = [2 1 2 1 2];
L3 = [3 3 3 3 1];
L4 = [10 0 2 0 0];
% concat all L1 to L4
L = [L1; L2; L3; L4];
% sort columns ascending
[~, ix] = sort(L, 1);
% last row of ix is the L1 to L4 index, we don't need the rest
ix = ix(end, :);
% color specification
col = {[1 0 0], [0 1 0], [0 0 1], [0 0.5 0.8]};
% plot
figure(1); cla; hold on;
for n = 1:length(X)
plot(X(n), Y(n), 'Color', col{ix(n)}, 'Marker', 'o');
end
You may define your colors as RGB values in the range [0; 1].

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by