フィルターのクリア

How to extract slider values from one .m file to another .m file

1 回表示 (過去 30 日間)
Syed Amer
Syed Amer 2018 年 1 月 30 日
回答済み: Jan 2018 年 1 月 30 日
I am new to matlab and just used the basics of guide of create a slider I am using the silder to adjust some variable values and extract them I have made one program for slider(GUI) and another for using the variable to perform the required operation
My question is how do i use the slider values to update the values in my main program.
EDIT : I am able to values in the slider program but I want the value in the other program Else, it would also be Okay if i can know how to run my normal code in the GUI program, like where i can write my program. Thanks for your response
  3 件のコメント
Adam
Adam 2018 年 1 月 30 日
編集済み: Adam 2018 年 1 月 30 日
It depends what your code structure and use workflow is. Do you want the code to run every time the slider is moved or just to use the current slider value when it is run?
(How to achieve what you want depends on those things I mean, not what Stephen said - that is absolutely always the case to never use those constructs and functions!)
Syed Amer
Syed Amer 2018 年 1 月 30 日
I want the code to update the new values of the slider and not just the initial values

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

回答 (2 件)

Rik
Rik 2018 年 1 月 30 日
get(handle_to_slider,'Value')
  2 件のコメント
Syed Amer
Syed Amer 2018 年 1 月 30 日
But that only allows me to take the value in the slider program, I want the value in the other program Else, it would also be Okay if i can know how to run my normal code in the GUI program, like where i can write my program. Thanks for your response
Rik
Rik 2018 年 1 月 30 日
The point is that you need a way to get the handle to the slider to your second function. How you do that is up to you. There are multiple method you could think of, most of which break easily.
Maybe the easiest and least likely to break is that you design your GUI creation function so that it returns its handles struct if nargin==1.
(What I mean with breaking is that the object no longer exist, but you try to use the handle. This can happen if you use a global or save to a mat file.)

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


Jan
Jan 2018 年 1 月 30 日
You can start the external function from inside the callback of the slider:
function SliderCallback(hObject, EvenData, handles)
Value = get(hObject, 'Value');
Your2ndFcn(Value);
end
Maybe the 2nd function has to update some output in the GUI. Then forward the handles struct also to allow to access all objects of the GUI.

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by