How to display an image every time a button is pushed in App designer?
12 次查看(过去 30 天)
显示 更早的评论
The question is based on creating a push button that displays an image in every instance the button is pressed. For example if the user pushes the button 5 times I would like 5 images to be displayed on the UI.Axes at different positions. I would like to know of a way how i can achieve this fucntion. I am fairly new to matlab app desinger. Any assistance is appreciated. The attached zip file is the code I had so far.
0 个评论
采纳的回答
Geoff Hayes
2021-12-17
@Kyle Ramphal - you might instead try inserting the n copies of an image within a larger image. Your larger image would act as the background, and you would then place your other images within it. For example,
mImg1 = imread('gfci.PNG');
mImg2 = imread('120V.png');
% create the background image which will be black
mBackgroundImg = uint8(zeros(1000,1000,3));
% create the figues, axes, and image
mHFig = figure;
mHAxes = axes;
mHImg = image(mHAxes, mBackgroundImg);
mImg1Size = size(mImg1);
mImg2Size = size(mImg2);
% insert the first image to the top left corner of the background image
mBackgroundImg(1:mImg1Size(1),1:mImg1Size(2),:) = mImg1;
% update the image object data
set(mHImg, 'CData', mBackgroundImg);
% position offset from top left corner of where the second image should be placed
mPosOffset = 500;
mBackgroundImg(mPosOffset:mImg2Size(1) + mPosOffset - 1,mPosOffset:mImg2Size(2) + mPosOffset - 1,:) = mImg2;
% update the image object data
set(mHImg, 'CData', mBackgroundImg);
You should be able to do something similar with your app so long as your background image is large enough and you know where you want to insert the new image.
2 个评论
Geoff Hayes
2021-12-18
@Kyle Ramphal - my mention of n is just to indicate any number of images that you add. You can use the above code within your app to allow the user to add any number of images, but you will need to decide the positions for them.
更多回答(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!