From: CyberFrog on
Hi all,

I have a cell array of strings:

str = {'13' '2' '3'}

ans =

'13' '2' '3'

How can I simply sort this in ascending order? I know ther are really numbers but I am surprrised between the sort, sortrows and even cellfun commands I cannot get to sort this in ascedning order? Can someone ease my pain please

Tnaks

CF
From: dpb on
CyberFrog wrote:
> Hi all,
>
> I have a cell array of strings:
>
> str = {'13' '2' '3'}
>
> ans =
> '13' '2' '3'
>
> How can I simply sort this in ascending order? I know ther are really
> numbers but I am surprrised between the sort, sortrows and even cellfun
> commands I cannot get to sort this in ascedning order? Can someone ease
> my pain please
....

Not sure...my version predates fully implemented cellfun so can't test
and therefore am not proficient w/ it but...

I think you need to nest str2double() to convert the strings to numeric
then apply sort() to its result

In my version the only way to get the strings to numeric is via for
loop...surely that's been improved but I don't know how, precisely other
than the above guess.

--
From: Sean on
"CyberFrog" <domlee55(a)hotmail.com> wrote in message <hv7ko1$got$1(a)fred.mathworks.com>...
> Hi all,
>
> I have a cell array of strings:
>
> str = {'13' '2' '3'}
>
> ans =
>
> '13' '2' '3'
>
> How can I simply sort this in ascending order? I know ther are really numbers but I am surprrised between the sort, sortrows and even cellfun commands I cannot get to sort this in ascedning order? Can someone ease my pain please
>
> Tnaks
>
> CF

%%%
>> C = {'123' '32' '145' '96' '3.14159'}'
>> sortrows(C) %works for me
%%%

I think what's confusing you is that it is not sorting by complete number but by first number since they're strings. I.e.
'13'<'7' since the '1' is first and '1' is less than '7'
If you want 7<13 make it numeric.

Good Luck!