Plotting scatter plot using X coordinate matrix and Y coordinate matrix

1 次查看(过去 30 天)
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 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2021-2-13
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.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2021-2-13
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...

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by