I want to import image on app designer with drop down button

17 Ansichten (letzte 30 Tage)
Hello everyone.
I want to import image on app designer. Also, I would like to swith the image when drop down items changed.
How can i do it?
% Value changed function: PatientIDDropDown
function PatientIDDropDownValueChanged(app, event)
value = app.PatientIDDropDown.Value;
if (value=='5648834')
I1 = imshow('CT1.png', 'Parent', app.image)
elseif (value=='5648834')
I2 = imshow('CT2.png', 'Parent', app.image)
elseif (value=='5648834')
I3 = imshow('CT3.png', 'Parent', app.image)
elseif (value=='5648834')
I4 = imshow('CT4.png', 'Parent', app.image)
end
end
I make my code like above. However I got error message
Specify a UIAxes as the value for 'Parent'.
Best regard, SUE
  1 Kommentar
Mohammad Sami
Mohammad Sami am 26 Mai 2020
I assume "image" a uiimage element. If that is true, set the ImageSource propery instead.
app.image.ImageSource = 'CT4.png'; %etc

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam Danz
Adam Danz am 26 Mai 2020
Bearbeitet: Adam Danz am 27 Mai 2020
Your error message tells you exactly what you need to do.
"Specify a UIAxes as the value for 'Parent'."
It looks like you're using the correct syntax but app.image apparenlty is not a UIAxes. You should assign a UIAxes as parent.
I1 = imshow('CT4.png', 'Parent', app.UIAxes)
% ^^^^^^^^^^ whatever your axis handle is
Also, instead of using if-elseif, consider using a switch case,
switch value
case '5648834'
I1 = imshow('CT1.png', 'Parent', app.image);
case '5648834'
I2 = imshow('CT2.png', 'Parent', app.image);
case '5648834'
I3 = imshow('CT3.png', 'Parent', app.image);
case '5648834'
I4 = imshow('CT4.png', 'Parent', app.image);
otherwise
error('Did not recognized patient ID ''%s''.', value)
end
Lastly, all of your conditions (and all of my cases) are the same value '5648834' which must be a mistake.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by