Login  Register

Re: Sorting arrays

Posted by LIM Soon Yew John (IMB) on Sep 21, 2017; 2:57am
URL: http://imagej.273.s1.nabble.com/Sorting-arrays-tp5019415p5019416.html

Hi Alex,

You can use control loops and "endsWith" as shown below:

Array1 = newArray("expt-c1-f", "expt-c1-t", "expt-c1-v", "expt-c2-f", "expt-c2-t", "expt-c2-v");
order = newArray("-t","-v", "-f");
Array2 = newArray(6);
counter = 0;
for(index=1; index<3; index++){
for(e=0; e<order.length; e++){
target = d2s(index,0)+order[e];
for(a=0; a<Array1.length; a++){
if(endsWith(Array1[a], target)){
Array2[counter] = Array1[a];
counter +=1;
}
}
}
}
Array.print(Array2);

Best Regards,
John

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Alex
Sent: Thursday, 21 September, 2017 4:58 AM
To: [hidden email]
Subject: Sorting arrays

Hi all,
I have a series of file names in an array that I'm trying to sort with imagej macro language.

expt1-c1-f

expt1-c1-t

expt1-c1-v

expt1-c2-f

expt1-c2-t

expt1-c2-v


I'd like to sort the array like this

expt1-c1-t

expt1-c1-v

expt1-c1-f

expt1-c2-t

expt1-c2-v

expt1-c2-f


Further, I'd prefer to be able to specify the order of the sort : e.g. specify [t, v, f] or [f, t, v] or [v, f, t], etc.


Sent from Yahoo Mail for iPhone

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
This e-mail and any attachments are only for the use of the intended recipient and may contain material that is confidential, privileged and/or protected by the Official Secrets Act. If you are not the intended recipient, please delete it or notify the sender immediately. Please do not copy or use it for any purpose or disclose the contents to any other person.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html