Azzera filtri
Azzera filtri

Open an image when push button is clicked in app designer

22 visualizzazioni (ultimi 30 giorni)
HI !
I have a push button in the app. I want the push button to open an image file ( file name will be pre-defined in the code) .
I do not want to browse the image file.
What syntax should I use to get this worked ?

Risposta accettata

Eli Chen
Eli Chen il 12 Mar 2021
Modificato: Eli Chen il 12 Mar 2021
Hi,
Assume you have the target image file at your working directory, for example, MatlabLogo.png. And you have a push button in your app. These steps can help you opening the image by clicking on the push button:
  1. Navigate to Component Browser, Select the push button in app tree, then define button clicking callback function name
2. Click the blue icon next to function name, you will be navigated to code view
3. Inside push button clicking callback function, you can use syntax like this:
% Button pushed function: Button
function showImage(app, event)
img = imread('MatlabLogo.png');
image(img);
end
When you run your app, and click this button, the image should be opened in Matlab Figure without browsing it
  3 Commenti
Eli Chen
Eli Chen il 15 Mar 2021
The error message says something is wrong at Line 202 in your app code, can you show me what code at Line 202?
Amit Patankar
Amit Patankar il 17 Mar 2021
HI @Eli Chen, Adding these lines of code to the app introduces error in line 202, otherwise there is no error in the app. before adding the lines of code, model was running fine.

Accedi per commentare.

Più risposte (1)

Amit Patankar
Amit Patankar il 17 Mar 2021
Hi @Eli Chen Please see thefollowing snapshot of code, The line where error lies comes in a non- editable part.
  9 Commenti
Amit Patankar
Amit Patankar il 17 Mar 2021
Unfortunately , As this work is confidential customer data, I wont be able to share app file.
As the error line mentiones, should I add UIAxes property in the app and some extra lines to the callback function ?
Capx
Capx il 20 Dic 2021
Modificato: Capx il 20 Dic 2021
@Eli Chen I've tried your code, and it works. I'm trying to do something similar; however, I would like the image displayed in two different image holders on the same window as the pushbutton rather than in a pop-up window.

Accedi per commentare.

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Prodotti


Release

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by