フィルターのクリア

How to plot the maximum regions given several functions in a 2D plot?

1 回表示 (過去 30 日間)
EllaD
EllaD 2023 年 7 月 21 日
コメント済み: EllaD 2023 年 7 月 21 日
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?

採用された回答

Walter Roberson
Walter Roberson 2023 年 7 月 21 日
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 件のコメント
Bruno Luong
Bruno Luong 2023 年 7 月 21 日
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)
idx = 5×5
3 2 3 2 1 2 3 2 1 1 2 3 3 1 3 1 2 3 1 1 1 1 2 3 2
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)
ans = 4×4
2.5000 2.5000 2.0000 1.2500 2.5000 2.7500 1.7500 1.5000 2.0000 2.7500 2.0000 1.5000 1.2500 2.0000 2.2500 1.7500
min(idx3,[],3)
ans = 4×4
2 2 1 1 2 2 1 1 1 2 1 1 1 1 1 1
max(idx3,[],3)
ans = 4×4
3 3 3 2 3 3 3 3 3 3 3 3 2 3 3 3
pcolor(idx);
It must have some odd algorithm to decide the color.
But never mind I rarely (never) use pcolor.
EllaD
EllaD 2023 年 7 月 21 日
Thank you all for the feedback on pcolor. Appreciate it. :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeographic Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by