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 件のコメント

Adam
Adam 2020 年 2 月 10 日
編集済み: Adam 2020 年 2 月 10 日
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 2020 年 2 月 10 日
I have attempted these techniques, however I am still unable to access the image file from another callback function
Guillaume
Guillaume 2020 年 2 月 10 日
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 2020 年 2 月 10 日
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 2020 年 2 月 10 日
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 2020 年 2 月 10 日
Yes, I think I do want to read the image.
Rik
Rik 2020 年 2 月 11 日
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 2020 年 2 月 11 日
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 2020 年 2 月 11 日
Thanks to everyone who helped.

サインインしてコメントする。

 採用された回答

Guillaume
Guillaume 2020 年 2 月 11 日

0 投票

"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);

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by