How to pass a variable to a function in GUI?
Mostra commenti meno recenti
Hi,
Please see the graphs shown below.
In part A (the part which will execute when button is pressed), you can see that I am trying to load a .mat file. There is a variable called 'RGB' saved in this .mat file.

And in part B, I am also trying to use the same variable RGB without loading it again.However, the RGB from part A would not be passed to part B just like that.

I also tried in part A I wrote:
handles.RGB=RGB;
and in part B I wrote:
RGB= handles.RGB
But it didn't work. Could anyone help please?
3 Commenti
Adam
il 26 Feb 2018
You missed the line
guidata( hObject, handles )
from what you say you tried. Without this 'handles' is just a local copy of the struct in pushbutton1_Callback and goes out of scope when the function ends.
Rather than using the command syntax of load it is recommended to use the function syntax, and load into an output variable (which is a structure). This will make it more obvious that the data has been loaded into that callback's workspace only:
S = load('Picture.mat');
handles.RGB = S.RGB;
guidata(hObject, handles) % you forgot this!
Salad Box
il 26 Feb 2018
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Interactive Control and Callbacks in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!