How to use images in drop down menu

3 views (last 30 days)
Noor Solangi
Noor Solangi on 10 Sep 2019
Answered: Bhargavi Maganuru on 13 Sep 2019
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
------

Answers (1)

Bhargavi Maganuru
Bhargavi Maganuru on 13 Sep 2019
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!

Categories

Find more on Desktop in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!