Sort Descend Scientific Notation Error
7 ビュー (過去 30 日間)
I've got a vector of numbers. The vector has some numbers stored with and without scientific notation.
Eg 0.01 and 9.8e-04.
When i try sorting these numbers in descending order, the sort function puts 9.8e-05 above 0.01, even though 0.01 is larger.
Can anyone help me so it sorts from largest to smallest based on the expanded values? I've been trying to convert the numbers in the matrix from scientific notation to standard form, but changing format has not helped, and i haven't been able to get rid of the scientific notation properly.
I've looked through past questions / answers and have not found an answer that has worked for me.
Any advice is appreciated.
I believe the issue may be that the numbers are considered strings, but unsure how to convert string scientific notation to numbers.
Example data and code:
[ APH 0.01
[~,idx] = sort(u(:,2),'descend');
sortedu = u(idx,:);
sortedu looks like:
edit: updated code.
Stephen23 2019 年 10 月 15 日
@Kiran Eswaran : please upload your original data in a .mat file, by clicking the paperclip button. Note that I wrote "original data": this means your original table u (or whatever it is called), before you tried to do any conversions.
回答 (1 件)
Jos (10584) 2019 年 10 月 14 日
編集済み: Jos (10584) 2019 年 10 月 14 日
You misuse the sort command. Simply:
sortedu = sort(u ,'descend')
would do :-)
Moreover, if you remove the semicolons, you would see that you have some strange results in between...
Ask yourself what u(:,2) does, and u(idx,:).
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!