Thread Subject: rearranging elements of a structure

Subject: rearranging elements of a structure

From: Juliette Salexa

Date: 8 Jul, 2009 21:08:01

Message: 1 of 3

I don't like the way when I apply the command:

files = dir(*.5);

I get a structure which automatically reorders the .5 files in my directory into alphabetical order. Is there away to rearrange all of the structure elements into a custom order very esaily ?? I tried opening the array editor and dragging and dropping the cells into my desired positions the way I can in excel but that didn't work ):

Subject: rearranging elements of a structure

From: Jan Simon

Date: 9 Jul, 2009 00:21:01

Message: 2 of 3

Dear Juliette Salexa!

> I don't like the way when I apply the command:
> files = dir(*.5);
> I get a structure which automatically reorders the .5 files in my directory into alphabetical order. Is there away to rearrange all of the structure elements into a custom order very esaily ??

I'm not sure, if it is "very easily", but if you want to sort the files by the creation date, use:

  Files = dir('*.5');
  [dum, v] = sort(datenum({Files.date}));
  Files = Files(v);

For Matlab 7.? DATENUM can be replaced, because DIR replies the numerical format already: ...sort({Files.datenum})...
For other orders, replace [v] by your favourite sequence.

Good luck, Jan

Subject: rearranging elements of a structure

From: Juliette Salexa

Date: 9 Jul, 2009 17:20:18

Message: 3 of 3

Thanks Jan Simon! That worked perfectly!

For anyone that wants to reorder elements of a struture in the future:
v=[2 5 3 1 4];
Files(v)=Files;

will make Files(2)=Files(1), Files(5)=Files(2), Files(3)=Files(3), etc ...

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

Contact us at files@mathworks.com