Fixing my counter statement.
9 次查看(过去 30 天)
显示 更早的评论
So I have two arrays (x and y) that are 324 long columns. I need to separate the each pair(x,y) of points into what quadrant the point falls into when graphed. For example if the first x and y are (-3,4) I need to put that point into an array of the other points in the data that fall in quadrant two. What am I doing wrong?
Q=[x y];
for counter=1:length(Q)
if x(counter)>0 && y(counter)>0
Q1=[x(x>0) y(y>0)'];
end
if x(counter)<0 && y(counter)>0
Q2=[x(x<0) y(y>0)'];
end
if x(counter)<0 && y(counter1)<0
Q3=[x(x<0) y(y<0)'];
end
if x(counter)>0 && y(counter1)<0
Q4=[x(x>0) y(y<0)'];
end
end
0 个评论
采纳的回答
the cyclist
2015-5-1
I would do it like this:
% Some pretend data
x = rand(324,1) - 0.5;
y = rand(324,1) - 0.5;
% First quadrant
Q1_index = (x>0) & (y>0);
Q1 = [x(Q1_index) y(Q1_index)]
% similar code for the other three quadrants ...
0 个评论
更多回答(1 个)
John D'Errico
2015-5-1
Why all the tests?
whichQuadrant = @(x,y) 1 + floor(mod(atan2d(y,x)/90,4));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!