# How to custom sort a vector with respect to another vector of unequal length

조회 수: 5 (최근 30일)
Muhammad Usman Saleem 2017년 11월 21일
댓글: Muhammad Usman Saleem 2017년 11월 29일
I have a vector Lon which I have created after spline interpolation of lon vector
Lon = [...
88.5000
88.0000
87.5000
87.0000
86.5000
86.0000
85.5000
85.0000
84.5000
84.0000
83.5000
83.0000
82.5000
82.0000
81.5000
81.0000
80.5000
80.0000
79.5000
79.0000]
I want to arrange Lon vector with respect to vector lon my lon vector is given below
lon =
88.5000
85.0000
81.0000
79.0000
80.0000
The vector Lon is in descending ordering after interpolation. I want such arrangement of elements in Lon vector
Lon=
88.5
88
87.5
87
86.5
86
85.5
85
84.5
84
83.5
83
82.5
82
81.5
81
79.5
79
80
80.5
Please check the arrangement of 3,4,5 element of lon. I want Lon should be in the same manner of lon .
Please guide me. I am stuck a lot in this sorting!
##### 댓글 수: 7이전 댓글 5개 표시이전 댓글 5개 숨기기
Jan 2017년 11월 27일
Dear Muhammad: Unfortunately I still do not understand, what the problem is. Which step does not work as you expect it? Where does the unwanted sorting happen? How are Lon and lon in your example related to each other?
Muhammad Usman Saleem 2017년 11월 29일
Dear @Jan, here is step by step explanation of my code and problem
These lines reading lat and lon vectors from my excel file
lat=file(:,3); % reading lat from file
lon=file(:,2); %reading lon from excel file
Here I am making the newlon vector which will be uniformly spaced start from min value of lon and end with max value of lon along with interval of 0.1
s=min(lon);
e=max(lon);
newlon=s:0.1:e;
generating lat variables from newlon vector with using spline interpolation method as below
newlat=spline(lon,lat,newlon);
Now newlat will be a row vector I want to convert this to column vector by these lines
newlat1=newlat.';
newlon1=newlon.';
lat1=lat.';
lon1=lon.';
After interpolation I see the newlat1 and newlon1 were need to flip up.
Lat=flipud(newlat1);
Lon=flipud(newlon1);
Problem
Now I am comparing the lon1 and newlon1 vector. I saw in lon1 vector, its first element is 85.5, second is 80, third is 81, fourth is 79, fifth is 80.
lon1 =
88.5000
85.0000
81.0000
79.0000
80.0000
I want to sort newlon1 vector such that its element in order all number above 88.5 then from 88.5 to 85 then after 85 to 81 then 81 to 79 and then 79 to 80. Then newlon1 vector will be in the same increasing or decreasing order like lon1 vector.
Here i am getting problem sir? Please assist me

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

### 답변 (1개)

John D'Errico 2017년 11월 22일
편집: John D'Errico 2017년 11월 22일
You appear to be looking to bin your data. Use histcounts. (REALLY!) Read the help.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Muhammad Usman Saleem 2017년 11월 24일
Dear I have edited my question. How you are guiding me about hiscounts? Dear this will just count bins in histogram. I want to arrange Lon vector with respect to lon vector. Will you share with me an example you are suggesting me?

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

### 카테고리

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

### Community Treasure Hunt

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

Start Hunting!

Translated by