Plotting scatter plot using X coordinate matrix and Y coordinate matrix

7 vues (au cours des 30 derniers jours)
Radhika Kulkarni
Radhika Kulkarni le 13 Fév 2021
Commenté : KALYAN ACHARJYA le 13 Fév 2021
Hello,
I have 2 matrices (18x76): one for x coordinate location and one for y coordinate location representing nodes.
I want to plot these nodes in a scatterplot using a for loop. I also want to have an if statement saying "if the x coordinate is greater than 15, don't plot a pixel there" and "if the y coordinate is greater than 3, don't plot a pixel there".
For example, matrix X(4,5) = 0.9 and matrixY(4,5) = 0.5196 so there should be a red circle on the graph at that location.
Here is the working code I have so far: Please let me know if this doesn't make sense. Any help would be appreciated!
for x_coor_col=1:76
for x_coor_row=1:18
for y_coor_col=1:76
for y_coor_row=1:18
if x_coor(x_coor_row,x_coor_col) > 15 | y_coor(y_coor_row,y_coor_col) > 3
%don't plot pixel
else
% plot a pixel at that location
end
end
end
end
end
  3 commentaires
Radhika Kulkarni
Radhika Kulkarni le 13 Fév 2021
at ( 0.9, 0.5196)
KALYAN ACHARJYA
KALYAN ACHARJYA le 13 Fév 2021
Is this ? DO Modify as per requiremnets. Still, I'm not clear about the question, so I've posted comments
x_coor=randi(20,[18,76]);
y_coor=randi(20,[18,76]);
mask=x_coor> 15 | y_coor > 3;
%Plot Data with red color
scatter(x_coor(mask),y_coor(mask),'ro','linewidth',2);
hold on;
% Donot Plot data with blue color
scatter(x_coor(~mask),y_coor(~mask),'b*','linewidth',2);
If you dont want 2nd one, just delete the last line.

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 13 Fév 2021
Don't need any loops
X=x_coor(:); Y=y_coor(:); % vector; not required to plot, just to keep original data unchanged
XLIM=15; YLIM=3; % the limits, use variables so can change easily
X(X>XLIM)=nan; Y(Y>YLIM)=nan; % plotting routines ignore NaNs
hSc=scatter(X,Y,2,'filled')
Fiddle with size, color and whether want filled or not to suit tastes...

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by