Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
overloading the new DIR command!!!

Subject: overloading the new DIR command!!!

From: Brett Shoelson

Date: 15 Jun, 2001 16:24:17

Message: 1 of 5

A recent question concerning overloading prompted me to post this:

In case anyone doesn't know it, the current (V6,R12) version of DIR returns
a structure, the elements of which ARE NOT NECESSARILY IN ALPHABETICAL
ORDER.

When I first loaded R12, much of my code suddenly started returning
erroneous results. I tracked it down to this change in the behavior of DIR.
TMW actually sent me an overload version of the function, and now my code
works properly again. But their "official" stance was that the documentation
for DIR doesn't claim that the structure is alphabetically
sorted--regardless of the fact that it was in previous versions.

USER BEWARE: if you rely on DIR to return an alpha-sorted structure, you
need to overload the function.

Regards,
Brett

--

***********************************************************************
Brett Shoelson, Ph.D.
brett.shoelson@joslin.harvard.edu
Home/work phone: 703/960-2470
***********************************************************************

Subject: overloading the new DIR command!!!

From: jacklam@math.uio.no (Peter J. Acklam)

Date: 15 Jun, 2001 23:03:28

Message: 2 of 5

"Brett Shoelson" <b@cox.rr.com> wrote:

> In case anyone doesn't know it, the current (V6,R12) version of
> DIR returns a structure, the elements of which ARE NOT
> NECESSARILY IN ALPHABETICAL ORDER.

In many cases, the order of the files doesn't matter, and if so,
then the time DIR spends sorting the names is just a waste. In
any case you can always do the sorting yourself.

> USER BEWARE: if you rely on DIR to return an alpha-sorted
> structure, you need to overload the function.

...or simply do the sorting yourself:

   d = dir(...); % possibly unsorted
   [junk, i] = sort({d.name});
   d = d(i); % sorted

Peter

--
"It is inhumane, in my opinion, to force people who have a genuine
medical need for coffee to wait in line behind people who apparently
view it as some kind of recreational activity."
             -- Dave Barry

Subject: overloading the new DIR command!!!

From: Abe Kohen

Date: 15 Jun, 2001 17:11:26

Message: 3 of 5


"Peter J. Acklam" <jacklam@math.uio.no> wrote in message
news:wksnh1jykg.fsf@math.uio.no...
> "Brett Shoelson" <b@cox.rr.com> wrote:
>
> > In case anyone doesn't know it, the current (V6,R12) version of
> > DIR returns a structure, the elements of which ARE NOT
> > NECESSARILY IN ALPHABETICAL ORDER.
>
> In many cases, the order of the files doesn't matter, and if so,
> then the time DIR spends sorting the names is just a waste. In
> any case you can always do the sorting yourself.
>
> > USER BEWARE: if you rely on DIR to return an alpha-sorted
> > structure, you need to overload the function.
>
> ...or simply do the sorting yourself:
>
> d = dir(...); % possibly unsorted
> [junk, i] = sort({d.name});
> d = d(i); % sorted
>
> Peter

Thank you for solving the "problem" so elegantly.

Abe

Subject: overloading the new DIR command!!!

From: Brett Shoelson

Date: 15 Jun, 2001 22:08:42

Message: 4 of 5

Yep, I agree that the order often doesn't matter. Just wanted to call folks'
attention to the fact for the times when it DOES matter. It's relatively
easy to sort the directory, but sometimes (as in my case of image processing
thousands of consecutive video frames), it can be difficult to tell that
they are not sorted. But without addressing the frames in order, video-image
processing is impossible.
Brett

"Peter J. Acklam" <jacklam@math.uio.no> wrote in message
news:wksnh1jykg.fsf@math.uio.no...
> "Brett Shoelson" <b@cox.rr.com> wrote:
>
> > In case anyone doesn't know it, the current (V6,R12) version of
> > DIR returns a structure, the elements of which ARE NOT
> > NECESSARILY IN ALPHABETICAL ORDER.
>
> In many cases, the order of the files doesn't matter, and if so,
> then the time DIR spends sorting the names is just a waste. In
> any case you can always do the sorting yourself.
>
> > USER BEWARE: if you rely on DIR to return an alpha-sorted
> > structure, you need to overload the function.
>
> ...or simply do the sorting yourself:
>
> d = dir(...); % possibly unsorted
> [junk, i] = sort({d.name});
> d = d(i); % sorted
>
> Peter
>
> --
> "It is inhumane, in my opinion, to force people who have a genuine
> medical need for coffee to wait in line behind people who apparently
> view it as some kind of recreational activity."
> -- Dave Barry

Subject: overloading the new DIR command!!!

From: jacklam@math.uio.no (Peter J. Acklam)

Date: 18 Jun, 2001 12:48:31

Message: 5 of 5

"Brett Shoelson" <b@cox.rr.com> wrote:

> Yep, I agree that the order often doesn't matter. Just wanted
> to call folks' attention to the fact for the times when it DOES
> matter. [...]

Perhaps the moral of the story is that if something isn't
documented, then don't assume anything about the behaviour.

There are things in MATLAB that aren't documented -- at least not
in the documentation you get with the HELP function -- so I too
tend to guess behaviour by trial and error. But doing so is a
little risky, because as we have seen now, undocumented behaviour
might change.

Peter

--
"It is inhumane, in my opinion, to force people who have a genuine
medical need for coffee to wait in line behind people who apparently
view it as some kind of recreational activity."
             -- Dave Barry

Tags for this Thread

No tags are associated with this thread.

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.

Contact us