Switch channel in macro

Hi,

We have had help to build a macro to analyze our images and have little knowledge as to how to make them ourself. I now want to switch channel from one to three or four. Can anyone help me point out which command that sets the channel and how to change it to another? I would be most grateful for all help.

// Get pixel size
getPixelSize(unit, pixelWidth, pixelHeight);

// Ask user to draw edge using 'Straight' selection tool
waitForUser("User input", "Draw edge with 'Straight'");
if (selectionType() != 5) {
	exit("Selection was not of type 'Straight'")
}
getSelectionCoordinates(xpoints_start, ypoints_start);
roiManager("Reset");
roiManager("Add");

// Ask user for measurement spacing and direction
Dialog.create("User Input");
Dialog.addNumber("Spacing (micron)", 10);
Dialog.addNumber("Repeats", 30);
items = newArray("Up", "Down", "Left", "Right");
Dialog.addRadioButtonGroup("Direction", items, 2, 2, "Up");
Dialog.show();
spacing_pixel = round(Dialog.getNumber() / pixelWidth);
spacing_micron = spacing_pixel * pixelWidth;
nr_repeats = Dialog.getNumber();
direction = Dialog.getRadioButton();

// Check the measurement direction
if (startsWith(direction, items[0])) {
	updown = 1;
	leftright = 0;
} else if (startsWith(direction, items[1])) {
	updown = -1;
	leftright = 0;
} else if (startsWith(direction, items[2])) {
	updown = 0;
	leftright = -1;
} else {
	updown = 0;
	leftright = 1;
}

// Construct a ROI for intensity measurements and move it away from the edge
intensity_list = newArray(nr_repeats);
for (i = 1; i <= nr_repeats; i++) {
	roiManager("Select", (i - 1) * 3);
	getSelectionCoordinates(xpoints, ypoints);
	makeLine(xpoints[0], ypoints[0], xpoints[0] + leftright * spacing_pixel, ypoints[0] - updown * spacing_pixel);
	roiManager("Add");
	makeLine(xpoints[1], ypoints[1], xpoints[1] + leftright * spacing_pixel, ypoints[1] - updown * spacing_pixel);
	roiManager("Add");
	makeLine(xpoints[0] + leftright * spacing_pixel, ypoints[0] - updown * spacing_pixel, xpoints[1] + leftright * spacing_pixel, ypoints[1] - updown * spacing_pixel);
	roiManager("Add");
	roiManager("Select", newArray((i - 1) * 3, (i - 1) * 3 + 1, (i - 1) * 3 + 2, (i - 1) * 3 + 3));
	roiManager("Combine");
	run("Set Measurements...", "mean redirect=None decimal=3");
	run("Measure");
	intensity_list[i - 1] = getResult("Mean", 0);
	run("Clear Results");
}
run("Select None");
roiManager("Show All without labels");

// Display in Results
run("Clear Results");
for (i = 0; i < nr_repeats; i++) {
	setResult("distance from edge (micron)", i, (i + 1) * spacing_micron);
	setResult("mean intensity (a.u.)", i, intensity_list[i]);
}

From https://imagej.nih.gov/ij/developer/macro/functions.html :

Stack.setChannel(n) - Displays channel n .

I recommend bookmarking that page, it’s my first point of reference for anything macro-related!

Thank you Erick, I will save this page for future references. But I can’t find any such command in the macro so I still don´t know as to where or how to change the channel it is using. I know it is now set to channel 1 and I would like to change it to channel 3. Do you know what parameter I need to change to do that?

Your macro is currently not prepared to analyze multiple channels.
In principle you have to repeat the command
run("Measure");
for all channels.

Switching the channels is the easiest part.
But to implement this the macro logic has to be modified substancially.
It seems as if you are searching for a maintainer of this code. Could that be?

I just realised this and was able to add the command for a specific channel. I will now do it for each channel. Thank you for your help!