Help: Pass data from seperate .m file to GUI .m file?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello everybody,
I have a .m file (named file 1) generated from .fig file and a seperate .m file to calculate (named file 2). There're two values a and b from end user through GUI. These values will be passed to file 2 to calculate a + b. The result will be assigned to res variable in file 2. When user pushes a button in GUi, it will show res variable in the static text field.
Could someone please tell me how to do it?
The code of .m file 1. I also attached files below.
function y=file2(handles)
clc
a=str2num(get(handles.a,'string'));
b=str2num(get(handles.b,'string'));
res=a+b;
%
2 件のコメント
回答 (1 件)
Stephen23
2014 年 10 月 8 日
2 件のコメント
Stephen23
2014 年 10 月 8 日
編集済み: Stephen23
2014 年 10 月 8 日
Yes, the set command needs to happen in the pushbutton's callback function . For this you can easily define your own anonymous function which includes the set command.
The concept is this:
- The button is pressed.
- The button calls its callback function (which you can define).
- Your callback function sets the string value (or does anything else that you want to do).
This is explained in more detail in the docs:
参考
カテゴリ
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!