How can I make a 2D color plot

3 ビュー (過去 30 日間)
felix kok
felix kok 2018 年 7 月 5 日
コメント済み: Star Strider 2018 年 7 月 6 日
I have an NxM matrix (B) containing values. Every value N,M corresponds to a value at that position in x,y (similarly, I also have the meshgrids for x and y). What I would like to plot is simply a contour in x,y giving in binary state whether or not the value of B is higher than a threshold. I.e. a plot where every value above threshold gives a red dot and every value below threshold gives a green dot. How do I do this?
Thanks in advance!
  2 件のコメント
jonas
jonas 2018 年 7 月 5 日
Do you want something like this?
felix kok
felix kok 2018 年 7 月 5 日
Yes please!

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

回答 (1 件)

Star Strider
Star Strider 2018 年 7 月 5 日
Try this:
x = rand(1, 5); % Create Data
y = rand(1, 7); % Create Data
[X,Y] = ndgrid(x,y);
B = rand(5, 7); % Create Data
Bidx = B >= 0.5; % Threshold Index
B1 = B .* Bidx; % Matrix == Threshold Condition
B1(B1 == 0) = NaN; % Only Plot Points Meeting Criteria
B2 = B .* ~Bidx; % Matrix ~= Threshold Condition
B2(B2 == 0) = NaN; % Only Plot Points Meeting Criteria
figure
scatter3(X(:), Y(:), B1(:), '.r')
hold on
scatter3(X(:), Y(:), B2(:), '.g')
hold off
view(0, 90)
  2 件のコメント
felix kok
felix kok 2018 年 7 月 6 日
編集済み: felix kok 2018 年 7 月 6 日
Thanks a lot! However, when I try your code I get the following (see image)
Star Strider
Star Strider 2018 年 7 月 6 日
You did not specify the result you wanted.
Try this:
x = rand(1, 50); % Create Data
y = rand(1, 70); % Create Data
[X,Y] = ndgrid(x,y);
B = rand(numel(x), numel(y)); % Create Data
Bidx = B >= 0.5; % Threshold Index
B1 = B .* Bidx; % Matrix == Threshold Condition
figure
hs = surf(X, Y, B1)
set(hs, 'EdgeColor','none')
view(0, 90)
colormap([1 0 0; 0 1 0])
colorbar
Experiment to get different results.

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

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by