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!