How can I make a 2D color plot
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Star Strider
am 5 Jul. 2018
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 Kommentare
Star Strider
am 6 Jul. 2018
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.
Siehe auch
Kategorien
Mehr zu Surface and Mesh 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!
