Setting different images on slider in app designer
8 ビュー (過去 30 日間)
古いコメントを表示
Kutay Kutlay
2021 年 2 月 19 日
編集済み: Sahithi Kanumarlapudi
2021 年 2 月 23 日
Hello all,
I want to make a gui to to show different pictures at different values in slider. Also, I want to show these pictures in the same window when the slider changes the new picture should replace the old one. Right now I am using different buttons for different times rather than using slider also, images appear in new window.
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: Button
function ButtonPushed(app, event)
f = uifigure;
im = uiimage(f);
im.ImageSource = 'example1.png';
end
% Button pushed function: Button_7
function Button_7Pushed(app, event)
f = uifigure;
im = uiimage(f);
im.ImageSource = 'example2.png';
end
Ideas for help?
If you need any other clarifications, let me know.
0 件のコメント
採用された回答
Sahithi Kanumarlapudi
2021 年 2 月 22 日
編集済み: Sahithi Kanumarlapudi
2021 年 2 月 23 日
Hi,
I understand that you want to display different images for different values of slider respectively. 'ValueChangedFcn' of 'uislider' could help you achive that. This function would be invoked when the value of slider is changed.
Create a figure with no image initially (may be as a public property) and you can change the 'ImageSource'for each value of slider, so that you can display different images on the same figure.
Here is an example snippet
properties (Access = public)
fig1 = uifigure();% figure to display the image
end
sld = uislider(fig,...
'Position',[100 75 120 3],...
'ValueChangedFcn',@(sld,event) updateImage(sld,cg));
function updateImage(sld,cg)
value = app.Slider.Value;
if (value == 2)
im = uiimage(app.fig1);
im.ImageSource = 'peppers.png';
end
end
You can refer to the following links for further info
Hope this helps!
1 件のコメント
Adam Danz
2021 年 2 月 22 日
Since sliders are continuous and your set of images are discrete, you might want to change the slider behavior to behave as though it were discrete (instructions).
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Develop uifigure-Based Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!