How to plot the maximum regions given several functions in a 2D plot?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
EllaD
am 21 Jul. 2023
Kommentiert: EllaD
am 21 Jul. 2023
I have three functions A(i,j), B(i,j), and C(i,j) which are functions of i and j , where a<i<b and a<j<b.
I want to distinguish and plot regions where each of these functions has the maximum value. Can someone please help me get started?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1439353/image.png)
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 21 Jul. 2023
idx = max(cat(3, A, B, C), [], 3);
cmap = [.3 0 0; %light red
0 .5 0; %light green
0 0 .8]; %blue
pcolor(idx); colormap(cmap)
xlabel('i'); ylabel('j')
fake(1) = plot(nan, nan, 'DisplayName', 'A', 'Color', cmap(1));
fake(2) = plot(nan, nan, 'DisplayName', 'B', 'Color', cmap(2));
fake(3) = plot(nan, nan, 'DisplayName', 'C', 'Color', cmap(3));
legend(fake)
10 Kommentare
Bruno Luong
am 21 Jul. 2023
It is still not clear to me how pcolor graphical result has 3 colors, and not more as I assume it takes the average.
A=rand(5);
B=rand(5);
C=rand(5);
[~,idx] = max(cat(3, A, B, C), [], 3)
idx3 = cat(3,idx(1:end-1,1:end-1), ...
idx(1:end-1,2:end), ...
idx(2:end,2:end), ...
idx(2:end,1:end-1));
mean(idx3,3)
min(idx3,[],3)
max(idx3,[],3)
pcolor(idx);
It must have some odd algorithm to decide the color.
But never mind I rarely (never) use pcolor.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Geographic Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!