I have written a code to divide L pairs (coordinates) according to 4 quadrants:
L=input('Enter the number of pairs: ');
tr=randi(10,L,2);
xy=sortrows(tr);
a=1;
b=1;
c=1;
d=1;
for ii=1:10
if xy(ii,1)<=5 && xy(ii,2)<=5
xy1(a,:)=xy(ii,:);
a=a+1;
elseif xy(ii,1)>5 && xy(ii,1)<11 && xy(ii,2)<=5
xy2(b,:)=xy(ii,:);
b=b+1;
elseif xy(ii,1)>5 && xy(ii,1)<11 && xy(ii,2)>5 && xy(ii,2)<11
xy3(c,:)=xy(ii,:);
c=c+1;
elseif xy(ii,1)<=5 && xy(ii,2)>5 && xy(ii,2)<11
xy4(d,:)=xy(ii,:);
d=d+1;
end
end
There is a main array xy(Lx2) which takes random integer pairs and then divides them into 4 more additional arrays: xy1, xy2, xy3, xy4. The 2 dividing lines are x=5 and y=5. Starting from bottom-left and going in anticlockwise direction to top left.

댓글 수: 2

Rik
Rik 2018년 6월 17일
What is exactly your question? Would you like to know how to un-loop this? Or how to make it more adaptable to different division lines?
Vatsal Gupta
Vatsal Gupta 2018년 6월 18일
This is the quadrant system I'm referring to. xy will 'L' contain coordinate point pairs and these points will be divided into 4 arrays xy1 (I), xy2(II), xy3(III), and xy4(IV).

댓글을 달려면 로그인하십시오.

 채택된 답변

Rik
Rik 2018년 6월 18일

0 개 추천

You still haven't explained what your question is, so I'm going to assume you want to un-loop this. The code below yields the same results as yours, but does it without a loop (and won't result in an error for L<10).
L=input('Enter the number of pairs: ');
tr=randi(10,L,2);
xy=sortrows(tr);
index1=xy(:,1)<=5 & xy(:,2)<=5;
xy1=xy(index1,:);
a=size(xy1,1);
index2=xy(:,1)>5 & xy(:,1)<11 & xy(:,2)<=5;
xy2=xy(index2,:);
b=size(xy2,1);
index3=xy(:,1)>5 & xy(:,1)<11 & xy(:,2)>5 & xy(:,2)<11;
xy3=xy(index3,:);
c=size(xy3,1);
index4=xy(:,1)<=5 & xy(:,2)>5 & xy(:,2)<11;
xy4=xy(index4,:);
d=size(xy4,1);

댓글 수: 1

Vatsal Gupta
Vatsal Gupta 2018년 6월 19일
I think i explained the question well. Although i have found a solution, thanks for your efforts :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

제품

질문:

2018년 6월 17일

댓글:

2018년 6월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by