How to use a drop down menu to show an image based on selection.

조회 수: 14 (최근 30일)
Daniel
Daniel 2022년 11월 5일
댓글: Fazlollah 2023년 2월 16일
I am trying to create an app component that shows solar radiation on the earth. the user will use a drop down menu and select a region on earth( North America, Asia....). Then I want the image to be displayed on the image app after they select a region. What is the best approach.

답변 (1개)

Mario Malic
Mario Malic 2022년 11월 6일
Hello,
I would put those pictures in a cell array
images = cell(5,1);
images{1} = imread("path"); % and so on
Define ItemsData property in the DropDown component to take numeric value from 1 to n-pictures
app.DropDown.ItemsData = 1:5;
Then, you are able to use the Value, even if it's a character array, it will take the ItemsData value which you can use to index into cell array with images.
images{app.DropDown.Value}
  댓글 수: 5
Mario Malic
Mario Malic 2022년 11월 7일
편집: Mario Malic 2022년 11월 7일
I would definitely suggest you to do few basic programs and maybe MATLAB Onramp before you proceed.
% a = cell{5,1} is not the way to initialize a cell array
The choice for callback wasn't appropriate. Furthermore, read on properties of the apps and how to properly use them within the different callbacks.
You need to redo your paths for apps, as I changed some code for images to test it on my PC.
Fazlollah
Fazlollah 2023년 2월 16일
Great Answer, thank you. you also added a private property "image".

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by