Hi,
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:
u =
[ APH 0.01
GPT 9.8e-04
CPH 6.4e-05]
[~,idx] = sort(u(:,2),'descend');
sortedu = u(idx,:);
sortedu looks like:
sortedu =
[GPT 9.8e-04
CPH 6.4e-05
APH 0.01]
Thanks,
Kiran
edit: updated code.
4 Comments
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/485189-sort-descend-scientific-notation-error#comment_756034
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/485189-sort-descend-scientific-notation-error#comment_756034
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/485189-sort-descend-scientific-notation-error#comment_756233
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/485189-sort-descend-scientific-notation-error#comment_756233
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/485189-sort-descend-scientific-notation-error#comment_756234
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/485189-sort-descend-scientific-notation-error#comment_756234
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/485189-sort-descend-scientific-notation-error#comment_756291
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/485189-sort-descend-scientific-notation-error#comment_756291
Sign in to comment.