MATLAB Answers

0

How to use images in drop down menu

Asked by Noor Solangi on 10 Sep 2019
Latest activity Answered by 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
------

  0 Comments

Sign in to comment.

1 Answer

Answer by 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!

  0 Comments

Sign in to comment.