Plotting scatter plot using X coordinate matrix and Y coordinate matrix
조회 수: 2 (최근 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
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!