App designer - using a single variable to return multiple indices

1 次查看(过去 30 天)
Hi folks,
I am trying to pass two indices into a function but am currently failing as I'm sure I'm doing it wrong.
I tried to do this by defining an array, positionVector, which contains the indices I want to pass in pairs of 2, then using an iterator to pass these arguments to the function.
Is there a better way of doing this without hardcoding the positions?
Thanks
function ROI(app, index1, index2)
hold (app.Image, "on")
plot(app.Image, index1, index2, app.innerMarkerStyle, 'MarkerSize', app.CrosshairThickness.Value, 'Color', app.crossHairColour);
plot(app.Image, index1, index2, app.outerMarkerStyle, 'MarkerSize', app.CrosshairThickness.Value, 'Color', app.crossHairColour);
end
function DisplayCrosshairs(app)
I = imshow(app.currentImage, "Parent", app.Image);
app.Image.XLim = [0 I.XData(2)];
app.Image.YLim = [0 I.YData(2)];
app.Width = app.Image.XLim;
app.Height = app.Image.YLim;
quarterHeight = app.Height(1)+range(app.Height)*0.25;
halfHeight = app.Height(1)+range(app.Height)*0.5;
threeQuarterHeight = app.Height(1)+range(app.Height)*0.75;
quarterWidth = app.Width(1)+range(app.Width)*0.25;
halfWidth = app.Width(1)+range(app.Width)*0.5;
threeQuarterWidth = app.Width(1)+range(app.Width)*0.75;
positionVector = {quarterHeight quarterWidth; quarterHeight halfWidth; quarterHeight threeQuarterWidth; halfHeight quarterWidth; halfHeight halfWidth; halfHeight threeQuarterWidth; threeQuarterHeight quarterWidth; threeQuarterHeight halfWidth; threeQuarterHeight threeQuarterWidth};
checkMatrix = [app.TopLeft.Value app.TopMiddle.Value app.TopRight.Value app.CentreLeft.Value app.CentreMiddle.Value app.CentreRight.Value app.BottomLeft.Value app.BottomMiddle.Value app.BottomRight.Value];
app.numSamplesPerImage = sum(checkMatrix, 1:9);
for i = 1 : 9
if checkMatrix(i) == 1
ROI(app, positionVector{i});
end
end
end

采纳的回答

Mohammad Sami
Mohammad Sami 2021-3-31
编辑:Mohammad Sami 2021-3-31
Change it as follows
ROI(app, positionVector{i,:}); %row i, all columns

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by