How to use images in drop down menu

3 ビュー (過去 30 日間)
Noor Solangi
Noor Solangi 2019 年 9 月 10 日
回答済み: Bhargavi Maganuru 2019 年 9 月 13 日
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!

カテゴリ

Help Center および File ExchangeDesktop についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by