Azzera filtri
Azzera filtri

Get final slider value in workspace

1 visualizzazione (ultimi 30 giorni)
JM
JM il 11 Dic 2017
Modificato: JM il 12 Dic 2017
I am new to Matlab GUI, so presenting a highly simplified version of the actual case I am trying to put together. Basically, I want to crudely fit measured data to a fitting function to get initial values for the parameters in my fitting function in order to do proper fitting (using say lsqnonlin.m). My main script is
subplot('position',[0.1 0.3 0.8 0.6]); % subplot to hold plot
x=linspace(0,10,1000); KnownFunc = sin (2.35*x); plot(x,KnownFunc);
ht=uicontrol('Style', 'text', 'String', 'Parameter Value','Position', [150 50 90 30]); % some text for description
hs= uicontrol('Style', 'slider', 'Min',0,'Max', 10, 'Position', [250 50 200 30],'Callback', @PlotGUI); % define slider
hp = uicontrol('Style', 'PushButton','String', 'Fitting done','Position', [50 50 90 30], 'Callback', @(src,evt)disp(get(hs,'value')));
and PlotFig.m function is
function PlotGUI(hObject,eventData) % eventData not used
Param = get(hObject,'Value');
uicontrol('Style', 'text', 'String', num2str(Param),'Position', [460 55 60 20]);
x=linspace(0,10,1000);
k = Param;
KnownFunc = sin (2.35*x); % will be replaced by measured data
FittingFunc = sin(k*x); % a fitting function
plot(x,KnownFunc); hold on;
plot (x, FittingFunc); hold off;
I have made some progress and the above works, but I am unable to get the final chosen value of the slider (when the fitting-function matches the known-function visually) into the work-space for use by another function? I would like to get the final slider value when the push button saying ('fitting done') is pressed. I would like to execute
sliderValue = get (hs, 'Value');
after the push button is pressed. Cannot figure out how to do this at the moment. I can only display it at the moment.
Also, why does making PlotGUI a function of x (i.e. PlotGUI(hObject,eventData, x)) break the code?
I need to understand how to do this two fitting parameters, but I am struggling with one. Any inputs/direction will be very helpful. Thanks.

Risposte (0)

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