필터 지우기
필터 지우기

Random set of vectors and sort them via the x axis

조회 수: 2 (최근 30일)
Raz134
Raz134 2020년 12월 5일
댓글: Rik 2020년 12월 8일
Hello, i created a script which creates N amount of random vectors (with random set of x and y coordinates), where you can decide how many you want to be created. Is there a way to sort them in an ascending fasion via the x coordiantes and if x coordinates are the same via the y coordinate? I cant seem to make it work.
How can i sort these vectors?
N = input('Wieviele Vektoren wollen Sie erzeugen?:');
Asize = [50,50];
[Ix,Iy] = ind2sub(Asize,randperm(prod(Asize),N));
I = [Ix',Iy']

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2020년 12월 5일
Have a look at the help and documentation of the function sortrows. Also (if this is a educational programming task) read the help and documentation of the function sort and make use of that in a step-by-step algorithm.
HTH

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by