How to use images in drop down menu

12 次查看(过去 30 天)
I'm using a drop down menu which includes 5 different options for different calculations, My objective is whenever I touch option 1, specific image should appear. this goes for the rest of the options as well. I'm using this code, but there seems to be some problem with it. My first option is called "Inverting"
It shows error Matrix dimensions must agree.
-----
value = app.drop.Value;
global image1
if value == 'Inverting'
[filename, pathname] =uigetfile({'*.jpg'},'File Selector');
fullpathname=strcat(pathname,filename);
image1= imread(fullpathname);
imshow(image1,'Parent',app.UIAxes);
end
------

回答(1 个)

Bhargavi Maganuru
Bhargavi Maganuru 2019-9-13
Matrix dimensional error is because, value and options are compared using ‘==’ operator, it gives error when the length of the value differs from option length. Use strcmp instead of ‘==’ operator, which compare strings of different length.
The line
value = app.drop.Value;
in your code also gives error as there is no method or property named drop, use DropDown instead.
You can use following code to display image after your select first option “Inverting” from DropDown menu.
function DropDownValueChanged(app, event)
value = app.DropDown.Value;
global a
if strcmp(value,'Inverting')
[filename, pathname] =uigetfile({'*.jpg'},'File Selector');
fullpathname=strcat(pathname,filename);
a=imread(fullpathname);
imshow(a,'parent',app.UIAxes);
end
end
For more information about strcmp follow the link https://www.mathworks.com/help/matlab/ref/strcmp.html
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by