Sharing data between callback functions

Hi, so in one callback function, I have the code,
file = uigetfile('*.jpg');
I would like to acess this file from a different callback function. However when I run the second callback, i get the error, "unrecognized function"
How do I allow the file to be acessed from other callback functions?

9 comentarios

Adam
Adam el 10 de Feb. de 2020
Editada: Adam el 10 de Feb. de 2020
By the way, if you'd typed what you wrote as the title of this question into the Matlab help, this would have been one of the first 3 links it takes you to - it should always be your first port of call as it is often much faster than asking in the forum and you learn more often too!
Oliver Ferenczi
Oliver Ferenczi el 10 de Feb. de 2020
I have attempted these techniques, however I am still unable to access the image file from another callback function
Guillaume
Guillaume el 10 de Feb. de 2020
I have attempted these techniques
Then show us what you tried, so we can tell you how to fix it. Also, state if this is using App Designer or GUIDE.
Oliver Ferenczi
Oliver Ferenczi el 10 de Feb. de 2020
I am using App Designer. I have tried to create a private property where i have written the code,
properties (Access = private)
file; % Description
end
and then called the file later with the code,
faceDetector = vision.CascadeObjectDetector;
bboxes = step(faceDetector, app.file);
This line gives me the error,
Error using vision.CascadeObjectDetector/validateInputsImpl (line 339)
Expected input number 2 to be one of these types:
uint8, uint16, double, single, int16
Rik
Rik el 10 de Feb. de 2020
Since it wants a numeric variable, are you sure you don't need to read the image instead of providing a file name?
Oliver Ferenczi
Oliver Ferenczi el 10 de Feb. de 2020
Yes, I think I do want to read the image.
Rik
Rik el 11 de Feb. de 2020
Then it probably makes sense to imread. Whether you want to set the image or the path as property is up to you.
Don't forget to validate the user input (so check if the user actually did select a file).
Oliver Ferenczi
Oliver Ferenczi el 11 de Feb. de 2020
The issue with imread is that I need to access the file that was chosen in another callback function. So I am not sure how to get the file name from the other callback function.
Oliver Ferenczi
Oliver Ferenczi el 11 de Feb. de 2020
Thanks to everyone who helped.

Iniciar sesión para comentar.

 Respuesta aceptada

Guillaume
Guillaume el 11 de Feb. de 2020
"The issue with imread is that I need to access the file that was chosen in another callback function. So I am not sure how to get the file name from the other callback function."
You already have done it! The issue with your original error, as pointed out by Rik is that you never read the image, just passed the filename instead of the image to the face detector.
So instead of:
bboxes = step(faceDetector, app.file);
simply:
faceimage = imread(app.file); %actually read the image
bboxes = step(faceDetector, faceimage);

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Preguntada:

el 10 de Feb. de 2020

Comentada:

el 11 de Feb. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by