Posted by
LIM Soon Yew John (IMB) on
Oct 16, 2017; 2:24am
URL: http://imagej.273.s1.nabble.com/Sorting-arrays-tp5019415p5019534.html
Hi Alex,
You can add one more “for” loop into the macro and declare the number of “expt” & “c” as shown below.
Array1 = newArray("expt1-c1-f", "expt1-c1-t", "expt1-c1-v", "expt1-c2-f", "expt1-c2-t", "expt1-c2-v","expt2-c1-f", "expt2-c1-t", "expt2-c1-v", "expt2-c2-f", "expt2-c2-t", "expt2-c2-v");
numExpt = 2; //Number of experiment
numC= 3; //Number of c
order = newArray("-t","-v", "-f");
size = Array1.length;
Array2 = newArray(size);
counter = 0;
for(expt=1; expt<=numExpt; expt++){
for(c=1; c<=numC; c++){
for(e=0; e<order.length; e++){
target = "expt"+d2s(expt,0)+"-c"+d2s(c,0)+order[e];
for(a=0; a<Array1.length; a++){
if(endsWith(Array1[a], target)){
Array2[counter] = Array1[a];
counter +=1;
}
}
}
}
}
Array.print(Array2);
Regards,
John
From: Alex [mailto:
[hidden email]]
Sent: Sunday, 15 October, 2017 6:48 AM
To:
[hidden email];
[hidden email]; LIM Soon Yew John <
[hidden email]>
Subject: Re: Sorting arrays
Just to be clearer ...
Array1 = newArray("expt1-c1-f", "expt1-c1-t", "expt1-c1-v", "expt1-c2-f", "expt1-c2-t", "expt1-c2-v","expt2-c1-f", "expt2-c1-t", "expt2-c1-v", "expt2-c2-f", "expt2-c2-t", "expt2-c2-v");
order = newArray("-t","-v", "-f");
Array2 = newArray(12);
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);
yeilds
expt1-c1-t, expt2-c1-t, expt1-c1-v, expt2-c1-v, expt1-c1-f, expt2-c1-f, expt1-c2-t, expt2-c2-t, expt1-c2-v, expt2-c2-v, expt1-c2-f, expt2-c2-f
I'd like to return
expt1-c1-t, expt1-c1-v, expt1-c1-f, expt1-c2-t, expt1-c2-v, expt1-c2-f, expt2-c1-t, expt2-c1-v, expt2-c1-f, expt2-c2-t, expt2-c2-v, expt2-c2-f
Thanks
Alex
On Saturday, October 14, 2017, 3:39:55 PM PDT, Alex <
[hidden email]<mailto:
[hidden email]>> wrote:
John,
This works great, but it does fail when I have more than one experiment ... for example ...
expt1-c1-t
expt1-c1-v
expt1-c1-f
expt1-c2-t
expt1-c2-v
expt1-c2-f
expt2-c1-t
expt2-c1-v
expt2-c1-f
expt2-c2-t
expt2-c2-v
expt2-c2-f
gets sorted as :
expt1-c1-t
expt2-c1-t
expt1-c1-v
expt2-c1-v
expt1-c1-f
expt2-c1-f
expt1-c2-t
expt2-c2-t
expt1-c2-v
expt2-c2-v
expt1-c2-f
expt2-c2-f
Any thoughts?
On Wednesday, September 20, 2017, 7:58:37 PM PDT, LIM Soon Yew John <
[hidden email]<mailto:
[hidden email]>> wrote:
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]<mailto:
[hidden email]>] On Behalf Of Alex
Sent: Thursday, 21 September, 2017 4:58 AM
To:
[hidden email]<mailto:
[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.htmlThis 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.htmlThis 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