How to pass a variable to a function in GUI?
1 回表示 (過去 30 日間)
古いコメントを表示
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170789/image.jpeg)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170790/image.jpeg)
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 件のコメント
Stephen23
2018 年 2 月 26 日
編集済み: Stephen23
2018 年 2 月 26 日
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!
採用された回答
Adam
2018 年 2 月 26 日
Personally I use guidata if I am creating a GUIDE UI, but there are various different approaches in that link
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!