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

Muhammad Usman Saleem (view profile)

on 21 Nov 2017
Latest activity Commented on by Muhammad Usman Saleem

Muhammad Usman Saleem (view profile)

on 29 Nov 2017
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!

Muhammad Usman Saleem (view profile)

on 27 Nov 2017
Dear @Jan;
lat=file(:,3); % reading lat from file
lon=file(:,2); %reading lon from excel file
s=min(lon);
e=max(lon);
newlon=s:0.1:e; % My input new lon vector through which I want to interpolate Latitude vector
newlat=spline(lon,lat,newlon); %my new lat
newlat1=newlat.'; % converting them to column vector
newlon1=newlon.';
lat1=lat.';
lon1=lon.';
Lat=flipud(newlat1); %flipping up the interpolated lat and lon
Lon=flipud(newlon1);
colorstring = {'c' 'm' 'k' 'r' 'g' 'b' 'w' 'y'}; %mt color for different plots
plot_d(Lon,Lat,colorstring{i},45,0.7); % plotting
I have attached my plot_d script as well as sample data in excel files of two sheets.
Jan

Jan (view profile)

on 27 Nov 2017
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 (view profile)

on 29 Nov 2017
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

Products

Answer by John D'Errico

John D'Errico (view profile)

on 22 Nov 2017
Edited by John D'Errico

John D'Errico (view profile)

on 22 Nov 2017

You appear to be looking to bin your data. Use histcounts. (REALLY!) Read the help.