Get final slider value in workspace
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!