Hi all,
I must be having a mental block but i can't think how to define a variable number of arrays within a loop. I'm looking for a way for the loop to be able to create a number of arrays based on a counter variable. So something like: channels = could be any number; array length = 5; (this is always known) for (i=0; i<channels; i++) { newArray = Ch + i [array length] } I'd like the newly defined arrays to have the same name "Ch" plus an incremental number which comes from "i" but i don't know how to declare the array name to have a variable included. Is this possible in the macro language? I did a google search and came across a thread where someone had suggested importing the java utility "array list" but this looked like quite a complicated solution. Thanks for the help, Matt -- Matt Pearson Microscopy Facility MRC Human Genetics Unit Institute of Genetics and Molecular Medicine (IGMM) University of Edinburgh Crewe Road EH4 2XU -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Good day Matt,
I'm not perfectly sure but I fear that in the IJ-macro language you can't use a string str = "Ch" + i as a variable name. Dynamically generated variables may pose problems and arrays of arrays are impossible as well... Best Herbie ::::::::::::::::::::::::::::::::::::::::::::: Am 05.10.16 um 11:14 schrieb PEARSON Matthew: > Hi all, > > I must be having a mental block but i can't think how to define a variable number of arrays within a loop. I'm looking for a way for the loop to be able to create a number of arrays based on a counter variable. So something like: > > channels = could be any number; > array length = 5; (this is always known) > for (i=0; i<channels; i++) { > newArray = Ch + i [array length] > } > > I'd like the newly defined arrays to have the same name "Ch" plus an incremental number which comes from "i" but i don't know how to declare the array name to have a variable included. Is this possible in the macro language? I did a google search and came across a thread where someone had suggested importing the java utility "array list" but this looked like quite a complicated solution. > > Thanks for the help, > > Matt > > > -- > Matt Pearson > Microscopy Facility > MRC Human Genetics Unit > Institute of Genetics and Molecular Medicine (IGMM) > University of Edinburgh > Crewe Road > EH4 2XU > > > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by PEARSON Matthew
Hi Matt,
you can't have arrays of arrays or 2D arrays in the ImageJ macro language. The way out is flattening it out, so you have a longer 1D array: arrayLength=5; a = newArray(channels*arrayLength); for (i=0; i<channels; i++) a[i*arrayLength + 2] = someValueForArrayElement2; In other words, array elements 0-4 correspond to the first channel (i=0), 5-9 to the next channel (i=1), etc. Michael ________________________________________________________________ On 2016-10-05 11:14, PEARSON Matthew wrote: > Hi all, > > I must be having a mental block but i can't think how to define a variable number of arrays within a loop. I'm looking for a way for the loop to be able to create a number of arrays based on a counter variable. So something like: > > channels = could be any number; > array length = 5; (this is always known) > for (i=0; i<channels; i++) { > newArray = Ch + i [array length] > } > > I'd like the newly defined arrays to have the same name "Ch" plus an incremental number which comes from "i" but i don't know how to declare the array name to have a variable included. Is this possible in the macro language? I did a google search and came across a thread where someone had suggested importing the java utility "array list" but this looked like quite a complicated solution. > > Thanks for the help, > > Matt > > > -- > Matt Pearson > Microscopy Facility > MRC Human Genetics Unit > Institute of Genetics and Molecular Medicine (IGMM) > University of Edinburgh > Crewe Road > EH4 2XU > > > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Herbie and Michael,
Thanks for the feedback. Unfortunately i think i will have to elaborate on what i'm trying to do to see if the way i'm doing it seems odd to everyone else. I have a macro that can analyse n channels and the user is presented with a dialog at the start to ask how many channels there are in the image stack and in which order. From here each channel that they select for analysis is measured and all the results go into arrays for each set measurement and if i print out the arrays to the results table it looks like this: Image name Mean Min ID_Raw value value value value value value value value value value value value value value value value The first two rows say, represent the results for channel 1 and rows 3-4 are for channel 2 but we could have 3 or 4 channels. There will always be the same number of results (rows) per channel. Ideally i'd like to present the results for each channel in separate columns instead of consecutively in rows. However this is where i hit trouble because i need to split the parent arrays.length by the number of channels and produce new arrays for each channel, so the data would look like this when printed: Image name_ch1 Mean_ch1 Min_ch1 ID_Raw_ch1 Image name_ch2 Mean_ch2 Min_ch2 ID_Raw_ch2 value value value value value value value value value value value value value value value value It will be a batch macro so will analyse many images but each image will have the same number of channels per instance of running it at least. But you can see why i require the flexibility of defining different numbers of arrays and array names that somehow link to the channel number depending on how many channels are to be analysed. Is this all too much to ask? I could just tell the users that the results will be consecutive in rows that would save me a massive headache but i prefer the idea that the headings are per channel and its based on columns left to right. Thanks again! Matt -- Matt Pearson Microscopy Facility MRC Human Genetics Unit Institute of Genetics and Molecular Medicine (IGMM) University of Edinburgh Crewe Road EH4 2XU On 5 Oct 2016, at 10:48, Michael Schmid <[hidden email]<mailto:[hidden email]>> wrote: Hi Matt, you can't have arrays of arrays or 2D arrays in the ImageJ macro language. The way out is flattening it out, so you have a longer 1D array: arrayLength=5; a = newArray(channels*arrayLength); for (i=0; i<channels; i++) a[i*arrayLength + 2] = someValueForArrayElement2; In other words, array elements 0-4 correspond to the first channel (i=0), 5-9 to the next channel (i=1), etc. Michael ________________________________________________________________ On 2016-10-05 11:14, PEARSON Matthew wrote: Hi all, I must be having a mental block but i can't think how to define a variable number of arrays within a loop. I'm looking for a way for the loop to be able to create a number of arrays based on a counter variable. So something like: channels = could be any number; array length = 5; (this is always known) for (i=0; i<channels; i++) { newArray = Ch + i [array length] } I'd like the newly defined arrays to have the same name "Ch" plus an incremental number which comes from "i" but i don't know how to declare the array name to have a variable included. Is this possible in the macro language? I did a google search and came across a thread where someone had suggested importing the java utility "array list" but this looked like quite a complicated solution. Thanks for the help, Matt -- Matt Pearson Microscopy Facility MRC Human Genetics Unit Institute of Genetics and Molecular Medicine (IGMM) University of Edinburgh Crewe Road EH4 2XU -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Matt,
if you don't know in advance how many columns you have, you could use the ResultsTable. There you can easily have something like columnHeading = "ID_Raw_ch"+i; setResult(columnHeading, row, value); If you know the number of columns in advance, you could also use a String with tab-delimited or comma-delimited columns, where you simply append the result and a delimiter character, and a linefeed ("\n") when the file (line) is done. If the String will become long (> few thousands of entries), for performance reasons, best use the String Buffer: https://imagej.nih.gov/ij/developer/macro/functions.html#String Michael ________________________________________________________________ On 2016-10-05 12:32, PEARSON Matthew wrote: > Hi Herbie and Michael, > > Thanks for the feedback. Unfortunately i think i will have to elaborate on what i'm trying to do to see if the way i'm doing it seems odd to everyone else. > > I have a macro that can analyse n channels and the user is presented with a dialog at the start to ask how many channels there are in the image stack and in which order. From here each channel that they select for analysis is measured and all the results go into arrays for each set measurement and if i print out the arrays to the results table it looks like this: > > Image name Mean Min ID_Raw > value value value value > value value value value > value value value value > value value value value > > The first two rows say, represent the results for channel 1 and rows 3-4 are for channel 2 but we could have 3 or 4 channels. There will always be the same number of results (rows) per channel. Ideally i'd like to present the results for each channel in separate columns instead of consecutively in rows. However this is where i hit trouble because i need to split the parent arrays.length by the number of channels and produce new arrays for each channel, so the data would look like this when printed: > Image name_ch1 Mean_ch1 Min_ch1 ID_Raw_ch1 Image name_ch2 Mean_ch2 Min_ch2 ID_Raw_ch2 > value value value value value value value value > value value value value value value value value > > It will be a batch macro so will analyse many images but each image will have the same number of channels per instance of running it at least. But you can see why i require the flexibility of defining different numbers of arrays and array names that somehow link to the channel number depending on how many channels are to be analysed. > > Is this all too much to ask? I could just tell the users that the results will be consecutive in rows that would save me a massive headache but i prefer the idea that the headings are per channel and its based on columns left to right. > > Thanks again! > > Matt > > > -- > Matt Pearson > Microscopy Facility > MRC Human Genetics Unit > Institute of Genetics and Molecular Medicine (IGMM) > University of Edinburgh > Crewe Road > EH4 2XU > > > > > On 5 Oct 2016, at 10:48, Michael Schmid <[hidden email]<mailto:[hidden email]>> wrote: > > Hi Matt, > > you can't have arrays of arrays or 2D arrays in the ImageJ macro language. The way out is flattening it out, so you have a longer 1D array: > > arrayLength=5; > a = newArray(channels*arrayLength); > for (i=0; i<channels; i++) > a[i*arrayLength + 2] = someValueForArrayElement2; > > In other words, array elements 0-4 correspond to the first channel (i=0), 5-9 to the next channel (i=1), etc. > > Michael > ________________________________________________________________ > On 2016-10-05 11:14, PEARSON Matthew wrote: > Hi all, > > I must be having a mental block but i can't think how to define a variable number of arrays within a loop. I'm looking for a way for the loop to be able to create a number of arrays based on a counter variable. So something like: > > channels = could be any number; > array length = 5; (this is always known) > for (i=0; i<channels; i++) { > newArray = Ch + i [array length] > } > > I'd like the newly defined arrays to have the same name "Ch" plus an incremental number which comes from "i" but i don't know how to declare the array name to have a variable included. Is this possible in the macro language? I did a google search and came across a thread where someone had suggested importing the java utility "array list" but this looked like quite a complicated solution. > > Thanks for the help, > > Matt > > > -- > Matt Pearson > Microscopy Facility > MRC Human Genetics Unit > Institute of Genetics and Molecular Medicine (IGMM) > University of Edinburgh > Crewe Road > EH4 2XU > > > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Matt and Micheal,
In the case "you don't know in advance how many columns you have", can't you just use the "Array.concat(array1,array2)" instruction like: oldArray = Array.concat(oldArray, newlyExtendingArray); or am I missing something? My best regards, Philippe -----Message d'origine----- De : ImageJ Interest Group [mailto:[hidden email]] De la part de Michael Schmid Envoyé : mercredi 5 octobre 2016 13:48 À : [hidden email] Objet : Re: Creating "n" arrays in a loop Hi Matt, if you don't know in advance how many columns you have, you could use the ResultsTable. There you can easily have something like columnHeading = "ID_Raw_ch"+i; setResult(columnHeading, row, value); If you know the number of columns in advance, you could also use a String with tab-delimited or comma-delimited columns, where you simply append the result and a delimiter character, and a linefeed ("\n") when the file (line) is done. If the String will become long (> few thousands of entries), for performance reasons, best use the String Buffer: https://imagej.nih.gov/ij/developer/macro/functions.html#String Michael ________________________________________________________________ On 2016-10-05 12:32, PEARSON Matthew wrote: > Hi Herbie and Michael, > > Thanks for the feedback. Unfortunately i think i will have to elaborate on what i'm trying to do to see if the way i'm doing it seems odd to everyone else. > > I have a macro that can analyse n channels and the user is presented with a dialog at the start to ask how many channels there are in the image stack and in which order. From here each channel that they select for analysis is measured and all the results go into arrays for each set measurement and if i print out the arrays to the results table it looks like this: > > Image name Mean Min ID_Raw > value value value value > value value value value > value value value value > value value value value > > The first two rows say, represent the results for channel 1 and rows 3-4 are for channel 2 but we could have 3 or 4 channels. There will always be the same number of results (rows) per channel. Ideally i'd like to present the results for each channel in separate columns instead of consecutively in rows. However this is where i hit trouble because i need to split the parent arrays.length by the number of channels and produce new arrays for each channel, so the data would look like this when printed: > Image name_ch1 Mean_ch1 Min_ch1 ID_Raw_ch1 Image name_ch2 Mean_ch2 > Min_ch2 ID_Raw_ch2 value value value value value value value value > value value value value value value value value > > It will be a batch macro so will analyse many images but each image will have the same number of channels per instance of running it at least. But you can see why i require the flexibility of defining different numbers of arrays and array names that somehow link to the channel number depending on how many channels are to be analysed. > > Is this all too much to ask? I could just tell the users that the results will be consecutive in rows that would save me a massive headache but i prefer the idea that the headings are per channel and its based on columns left to right. > > Thanks again! > > Matt > > > -- > Matt Pearson > Microscopy Facility > MRC Human Genetics Unit > Institute of Genetics and Molecular Medicine (IGMM) University of > Edinburgh Crewe Road > EH4 2XU > > > > > On 5 Oct 2016, at 10:48, Michael Schmid > > Hi Matt, > > you can't have arrays of arrays or 2D arrays in the ImageJ macro language. The way out is flattening it out, so you have a longer 1D array: > > arrayLength=5; > a = newArray(channels*arrayLength); > for (i=0; i<channels; i++) > a[i*arrayLength + 2] = someValueForArrayElement2; > > In other words, array elements 0-4 correspond to the first channel (i=0), 5-9 to the next channel (i=1), etc. > > Michael > ________________________________________________________________ > On 2016-10-05 11:14, PEARSON Matthew wrote: > Hi all, > > I must be having a mental block but i can't think how to define a variable number of arrays within a loop. I'm looking for a way for the loop to be able to create a number of arrays based on a counter variable. So something like: > > channels = could be any number; > array length = 5; (this is always known) for (i=0; i<channels; i++) { > newArray = Ch + i [array length] } > > I'd like the newly defined arrays to have the same name "Ch" plus an incremental number which comes from "i" but i don't know how to declare the array name to have a variable included. Is this possible in the macro language? I did a google search and came across a thread where someone had suggested importing the java utility "array list" but this looked like quite a complicated solution. > > Thanks for the help, > > Matt > > > -- > Matt Pearson > Microscopy Facility > MRC Human Genetics Unit > Institute of Genetics and Molecular Medicine (IGMM) University of > Edinburgh Crewe Road > EH4 2XU > > > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Philippe,
yes, I agree, for small to medium amounts of data, concatenation of arrays is an easy way of doing it! If you have large amounts of data, doing many concatenation operations of large arrays (say, megabyte size) won't be efficient. Michael ________________________________________________________________ On 2016-10-05 14:07, Philippe CARL wrote: > Dear Matt and Micheal, > In the case "you don't know in advance how many columns you have", can't you > just use the "Array.concat(array1,array2)" instruction like: > oldArray = Array.concat(oldArray, newlyExtendingArray); > or am I missing something? > My best regards, > Philippe > > -----Message d'origine----- > De : ImageJ Interest Group [mailto:[hidden email]] De la part de > Michael Schmid > Envoyé : mercredi 5 octobre 2016 13:48 > À : [hidden email] > Objet : Re: Creating "n" arrays in a loop > > Hi Matt, > > if you don't know in advance how many columns you have, you could use the > ResultsTable. There you can easily have something like > columnHeading = "ID_Raw_ch"+i; > setResult(columnHeading, row, value); > > If you know the number of columns in advance, you could also use a String > with tab-delimited or comma-delimited columns, where you simply append the > result and a delimiter character, and a linefeed ("\n") when the file (line) > is done. > If the String will become long (> few thousands of entries), for performance > reasons, best use the String Buffer: > https://imagej.nih.gov/ij/developer/macro/functions.html#String > > Michael > ________________________________________________________________ > On 2016-10-05 12:32, PEARSON Matthew wrote: >> Hi Herbie and Michael, >> >> Thanks for the feedback. Unfortunately i think i will have to elaborate > on what i'm trying to do to see if the way i'm doing it seems odd to > everyone else. >> >> I have a macro that can analyse n channels and the user is presented with > a dialog at the start to ask how many channels there are in the image stack > and in which order. From here each channel that they select for analysis is > measured and all the results go into arrays for each set measurement and if > i print out the arrays to the results table it looks like this: >> >> Image name Mean Min ID_Raw >> value value value value >> value value value value >> value value value value >> value value value value >> >> The first two rows say, represent the results for channel 1 and rows 3-4 > are for channel 2 but we could have 3 or 4 channels. There will always be > the same number of results (rows) per channel. Ideally i'd like to present > the results for each channel in separate columns instead of consecutively in > rows. However this is where i hit trouble because i need to split the > parent arrays.length by the number of channels and produce new arrays for > each channel, so the data would look like this when printed: >> Image name_ch1 Mean_ch1 Min_ch1 ID_Raw_ch1 Image name_ch2 Mean_ch2 >> Min_ch2 ID_Raw_ch2 value value value value value value value value >> value value value value value value value value >> >> It will be a batch macro so will analyse many images but each image will > have the same number of channels per instance of running it at least. But > you can see why i require the flexibility of defining different numbers of > arrays and array names that somehow link to the channel number depending on > how many channels are to be analysed. >> >> Is this all too much to ask? I could just tell the users that the results > will be consecutive in rows that would save me a massive headache but i > prefer the idea that the headings are per channel and its based on columns > left to right. >> >> Thanks again! >> >> Matt >> >> >> -- >> Matt Pearson >> Microscopy Facility >> MRC Human Genetics Unit >> Institute of Genetics and Molecular Medicine (IGMM) University of >> Edinburgh Crewe Road >> EH4 2XU >> >> >> >> >> On 5 Oct 2016, at 10:48, Michael Schmid > <[hidden email]<mailto:[hidden email]>> wrote: >> >> Hi Matt, >> >> you can't have arrays of arrays or 2D arrays in the ImageJ macro language. > The way out is flattening it out, so you have a longer 1D array: >> >> arrayLength=5; >> a = newArray(channels*arrayLength); >> for (i=0; i<channels; i++) >> a[i*arrayLength + 2] = someValueForArrayElement2; >> >> In other words, array elements 0-4 correspond to the first channel (i=0), > 5-9 to the next channel (i=1), etc. >> >> Michael >> ________________________________________________________________ >> On 2016-10-05 11:14, PEARSON Matthew wrote: >> Hi all, >> >> I must be having a mental block but i can't think how to define a variable > number of arrays within a loop. I'm looking for a way for the loop to be > able to create a number of arrays based on a counter variable. So something > like: >> >> channels = could be any number; >> array length = 5; (this is always known) for (i=0; i<channels; i++) { >> newArray = Ch + i [array length] } >> >> I'd like the newly defined arrays to have the same name "Ch" plus an > incremental number which comes from "i" but i don't know how to declare the > array name to have a variable included. Is this possible in the macro > language? I did a google search and came across a thread where someone had > suggested importing the java utility "array list" but this looked like quite > a complicated solution. >> >> Thanks for the help, >> >> Matt >> >> >> -- >> Matt Pearson >> Microscopy Facility >> MRC Human Genetics Unit >> Institute of Genetics and Molecular Medicine (IGMM) University of >> Edinburgh Crewe Road >> EH4 2XU >> >> >> >> >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> >> >> >> The University of Edinburgh is a charitable body, registered in >> Scotland, with registration number SC005336. >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Guys,
I'll let my mind stew over this for a while but i'll try using the results table a bit more to do what i'm looking for. I'm not sure how concatenating arrays can work as again you need to know how many arrays you need and define them before you do this although if combined with pulling data from the results table perhaps that would work. Thanks again, Matt -- Matt Pearson Microscopy Facility MRC Human Genetics Unit Institute of Genetics and Molecular Medicine (IGMM) University of Edinburgh Crewe Road EH4 2XU On 5 Oct 2016, at 13:24, Michael Schmid <[hidden email]<mailto:[hidden email]>> wrote: Hi Philippe, yes, I agree, for small to medium amounts of data, concatenation of arrays is an easy way of doing it! If you have large amounts of data, doing many concatenation operations of large arrays (say, megabyte size) won't be efficient. Michael ________________________________________________________________ On 2016-10-05 14:07, Philippe CARL wrote: Dear Matt and Micheal, In the case "you don't know in advance how many columns you have", can't you just use the "Array.concat(array1,array2)" instruction like: oldArray = Array.concat(oldArray, newlyExtendingArray); or am I missing something? My best regards, Philippe -----Message d'origine----- De : ImageJ Interest Group [mailto:[hidden email]<http://LIST.NIH.GOV>] De la part de Michael Schmid Envoyé : mercredi 5 octobre 2016 13:48 À : [hidden email]<mailto:[hidden email]> Objet : Re: Creating "n" arrays in a loop Hi Matt, if you don't know in advance how many columns you have, you could use the ResultsTable. There you can easily have something like columnHeading = "ID_Raw_ch"+i; setResult(columnHeading, row, value); If you know the number of columns in advance, you could also use a String with tab-delimited or comma-delimited columns, where you simply append the result and a delimiter character, and a linefeed ("\n") when the file (line) is done. If the String will become long (> few thousands of entries), for performance reasons, best use the String Buffer: https://imagej.nih.gov/ij/developer/macro/functions.html#String Michael ________________________________________________________________ On 2016-10-05 12:32, PEARSON Matthew wrote: Hi Herbie and Michael, Thanks for the feedback. Unfortunately i think i will have to elaborate on what i'm trying to do to see if the way i'm doing it seems odd to everyone else. I have a macro that can analyse n channels and the user is presented with a dialog at the start to ask how many channels there are in the image stack and in which order. From here each channel that they select for analysis is measured and all the results go into arrays for each set measurement and if i print out the arrays to the results table it looks like this: Image name Mean Min ID_Raw value value value value value value value value value value value value value value value value The first two rows say, represent the results for channel 1 and rows 3-4 are for channel 2 but we could have 3 or 4 channels. There will always be the same number of results (rows) per channel. Ideally i'd like to present the results for each channel in separate columns instead of consecutively in rows. However this is where i hit trouble because i need to split the parent arrays.length by the number of channels and produce new arrays for each channel, so the data would look like this when printed: Image name_ch1 Mean_ch1 Min_ch1 ID_Raw_ch1 Image name_ch2 Mean_ch2 Min_ch2 ID_Raw_ch2 value value value value value value value value value value value value value value value value It will be a batch macro so will analyse many images but each image will have the same number of channels per instance of running it at least. But you can see why i require the flexibility of defining different numbers of arrays and array names that somehow link to the channel number depending on how many channels are to be analysed. Is this all too much to ask? I could just tell the users that the results will be consecutive in rows that would save me a massive headache but i prefer the idea that the headings are per channel and its based on columns left to right. Thanks again! Matt -- Matt Pearson Microscopy Facility MRC Human Genetics Unit Institute of Genetics and Molecular Medicine (IGMM) University of Edinburgh Crewe Road EH4 2XU On 5 Oct 2016, at 10:48, Michael Schmid <[hidden email]<mailto:[hidden email]><mailto:[hidden email]>> wrote: Hi Matt, you can't have arrays of arrays or 2D arrays in the ImageJ macro language. The way out is flattening it out, so you have a longer 1D array: arrayLength=5; a = newArray(channels*arrayLength); for (i=0; i<channels; i++) a[i*arrayLength + 2] = someValueForArrayElement2; In other words, array elements 0-4 correspond to the first channel (i=0), 5-9 to the next channel (i=1), etc. Michael ________________________________________________________________ On 2016-10-05 11:14, PEARSON Matthew wrote: Hi all, I must be having a mental block but i can't think how to define a variable number of arrays within a loop. I'm looking for a way for the loop to be able to create a number of arrays based on a counter variable. So something like: channels = could be any number; array length = 5; (this is always known) for (i=0; i<channels; i++) { newArray = Ch + i [array length] } I'd like the newly defined arrays to have the same name "Ch" plus an incremental number which comes from "i" but i don't know how to declare the array name to have a variable included. Is this possible in the macro language? I did a google search and came across a thread where someone had suggested importing the java utility "array list" but this looked like quite a complicated solution. Thanks for the help, Matt -- Matt Pearson Microscopy Facility MRC Human Genetics Unit Institute of Genetics and Molecular Medicine (IGMM) University of Edinburgh Crewe Road EH4 2XU -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by PEARSON Matthew
I would recommend printing the data to a text file that is tab or comma delimited or use the table output functions.
It could be one big text file or a text output file for each image with a matching name. Search the archives of this listserv for both solutions. ========================================================================= Michael Cammer, Microscopy Core & Skirball Institute, NYU Langone Medical Center Cell: 914-309-3270 Office: Skirball 2nd Floor main office, back right http://ocs.med.nyu.edu/microscopy & http://microscopynotes.com/ -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of PEARSON Matthew Sent: Wednesday, October 05, 2016 6:32 AM To: [hidden email] Subject: Re: Creating "n" arrays in a loop Hi Herbie and Michael, Thanks for the feedback. Unfortunately i think i will have to elaborate on what i'm trying to do to see if the way i'm doing it seems odd to everyone else. I have a macro that can analyse n channels and the user is presented with a dialog at the start to ask how many channels there are in the image stack and in which order. From here each channel that they select for analysis is measured and all the results go into arrays for each set measurement and if i print out the arrays to the results table it looks like this: Image name Mean Min ID_Raw value value value value value value value value value value value value value value value value The first two rows say, represent the results for channel 1 and rows 3-4 are for channel 2 but we could have 3 or 4 channels. There will always be the same number of results (rows) per channel. Ideally i'd like to present the results for each channel in separate columns instead of consecutively in rows. However this is where i hit trouble because i need to split the parent arrays.length by the number of channels and produce new arrays for each channel, so the data would look like this when printed: Image name_ch1 Mean_ch1 Min_ch1 ID_Raw_ch1 Image name_ch2 Mean_ch2 Min_ch2 ID_Raw_ch2 value value value value value value value value value value value value value value value value It will be a batch macro so will analyse many images but each image will have the same number of channels per instance of running it at least. But you can see why i require the flexibility of defining different numbers of arrays and array names that somehow link to the channel number depending on how many channels are to be analysed. Is this all too much to ask? I could just tell the users that the results will be consecutive in rows that would save me a massive headache but i prefer the idea that the headings are per channel and its based on columns left to right. Thanks again! Matt -- Matt Pearson Microscopy Facility MRC Human Genetics Unit Institute of Genetics and Molecular Medicine (IGMM) University of Edinburgh Crewe Road EH4 2XU On 5 Oct 2016, at 10:48, Michael Schmid <[hidden email]<mailto:[hidden email]>> wrote: Hi Matt, you can't have arrays of arrays or 2D arrays in the ImageJ macro language. The way out is flattening it out, so you have a longer 1D array: arrayLength=5; a = newArray(channels*arrayLength); for (i=0; i<channels; i++) a[i*arrayLength + 2] = someValueForArrayElement2; In other words, array elements 0-4 correspond to the first channel (i=0), 5-9 to the next channel (i=1), etc. Michael ________________________________________________________________ On 2016-10-05 11:14, PEARSON Matthew wrote: Hi all, I must be having a mental block but i can't think how to define a variable number of arrays within a loop. I'm looking for a way for the loop to be able to create a number of arrays based on a counter variable. So something like: channels = could be any number; array length = 5; (this is always known) for (i=0; i<channels; i++) { newArray = Ch + i [array length] } I'd like the newly defined arrays to have the same name "Ch" plus an incremental number which comes from "i" but i don't know how to declare the array name to have a variable included. Is this possible in the macro language? I did a google search and came across a thread where someone had suggested importing the java utility "array list" but this looked like quite a complicated solution. Thanks for the help, Matt -- Matt Pearson Microscopy Facility MRC Human Genetics Unit Institute of Genetics and Molecular Medicine (IGMM) University of Edinburgh Crewe Road EH4 2XU -- ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DQIF-g&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=a7cPTAvON0DS3AWSafA2PdCb7xjrzv0mUMoCQg3LnME&s=j-N6mGJ8AcDEzMc3tOLsAPcCzr34RPGKamSCzocy0gs&e= The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -- ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DQIF-g&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=a7cPTAvON0DS3AWSafA2PdCb7xjrzv0mUMoCQg3LnME&s=j-N6mGJ8AcDEzMc3tOLsAPcCzr34RPGKamSCzocy0gs&e= -- ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DQIF-g&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=a7cPTAvON0DS3AWSafA2PdCb7xjrzv0mUMoCQg3LnME&s=j-N6mGJ8AcDEzMc3tOLsAPcCzr34RPGKamSCzocy0gs&e= -- ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DQIF-g&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=a7cPTAvON0DS3AWSafA2PdCb7xjrzv0mUMoCQg3LnME&s=j-N6mGJ8AcDEzMc3tOLsAPcCzr34RPGKamSCzocy0gs&e= ------------------------------------------------------------ This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email. ================================= -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |