App designer - using a single variable to return multiple indices

조회 수: 1 (최근 30일)
Teshan Rezel
Teshan Rezel 2021년 3월 31일
편집: Mohammad Sami 2021년 3월 31일
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?
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);
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});

채택된 답변

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에서 Loops and Conditional Statements에 대해 자세히 알아보기




Community Treasure Hunt

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

Start Hunting!

Translated by