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

17 次查看(过去 30 天)
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 个评论
Mohammad Sami
Mohammad Sami 2020-5-26
I assume "image" a uiimage element. If that is true, set the ImageSource propery instead.
app.image.ImageSource = 'CT4.png'; %etc

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2020-5-26
编辑:Adam Danz 2020-5-27
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by