필터 지우기
필터 지우기

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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by