Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Adam
Adam il 30 Gen 2018
Modificato: Adam il 30 Gen 2018
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 il 30 Gen 2018
I want the code to update the new values of the slider and not just the initial values

Accedi per commentare.

Risposte (2)

Rik
Rik il 30 Gen 2018
get(handle_to_slider,'Value')
  2 Commenti
Syed Amer
Syed Amer il 30 Gen 2018
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 il 30 Gen 2018
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.)

Accedi per commentare.


Jan
Jan il 30 Gen 2018
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.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by