Open an image when push button is clicked in app designer

46 visualizaciones (últimos 30 días)
Amit Patankar
Amit Patankar el 11 de Mzo. de 2021
Editada: Capx el 20 de Dic. de 2021
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 ?

Respuesta aceptada

Eli Chen
Eli Chen el 12 de Mzo. de 2021
Editada: Eli Chen el 12 de Mzo. de 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 comentarios
Eli Chen
Eli Chen el 15 de Mzo. de 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 el 17 de Mzo. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

Amit Patankar
Amit Patankar el 17 de Mzo. de 2021
Hi @Eli Chen Please see thefollowing snapshot of code, The line where error lies comes in a non- editable part.
  9 comentarios
Amit Patankar
Amit Patankar el 17 de Mzo. de 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 el 20 de Dic. de 2021
Editada: Capx el 20 de Dic. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by