Thread Subject: HELP using SORTROWS with a cell array

Subject: HELP using SORTROWS with a cell array

From: Skip Albertson

Date: 2 May, 2008 15:42:18

Message: 1 of 2

I have a large cell array, A, and would like to sort it by rows. One of
the columns is date, stored as a string to get it into the array. Another is
distance, also stored as a string.

If I want to use SORTROWS by ascending date and distance, what is the
proper way to do it? I want to avoid mis-sorts like: 1, 10, 2, 3 versus
1, 2, 3, 10.

Thanks!

Subject: HELP using SORTROWS with a cell array

From: Peter Boettcher

Date: 2 May, 2008 15:49:59

Message: 2 of 2

Skip Albertson <alberts@ocean.washington.edu> writes:

> I have a large cell array, A, and would like to sort it by rows. One
> of the columns is date, stored as a string to get it into the array.
> Another is distance, also stored as a string.
>
> If I want to use SORTROWS by ascending date and distance, what is the
> proper way to do it? I want to avoid mis-sorts like: 1, 10, 2, 3
> versus
> 1, 2, 3, 10.

Either generate strings that lexically sort equivalent to the numeric
sort (01 instead of 1, etc.), or don't use strings for date. Instead
you could use datenums, which are easily converted back and forth to
human-readable strings. See "datenum", "datestr", and "datevec".

-Peter

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com