Slider GUI for fitting

I want to use slider to determine the lower limit when i try to fit a data, but nothing works. the fitting is appeared but nothing change when i drag the slider. no error message either. i use 'exclude by rule' fitting tool to imply the slider, how do i fix it?
here is the code im working on for callback slider. i was testing the slider feature for popvalue 2 first.
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sliderval = get(hObject, 'Value')
assignin('base', 'sliderVal', sliderval)
popvalue = get(hObject, 'value')
file=handles.file
data = xlsread(file)
t1 = data(:,1)
t2 = data(:,2)
if (popvalue == 2)
[xdata, ydata] = prepareCurveData(t1,t2)
excludedPoints = xdata < t1.sliderval
ft = fittype( 'Ms*(1-A/x-B/x^2)+(D*x)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Exclude = excludedPoints
[fitresult, gof] = fit( xdata, ydata, ft, opts);
plot( fitresult, xdata, ydata, excludedPoints );
grid on
xlabel('H')
ylabel('M')
Ms = fitresult.Ms
a = fitresult.A
b = fitresult.B
k = fitresult.D
set (handles.edit2,'String',num2str(a))
set (handles.edit3,'String',num2str(b))
set (handles.edit4,'String',num2str(k))
set (handles.edit5,'String',num2str(Ms))
elseif (popvalue == 3)
[xdata, ydata] = prepareCurveData(t1, t2);
ft = fittype( 'Ms*(1-A/x-B/x^2)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
[fitresult2, gof2] = fit( xdata, ydata, ft, opts );
plot( fitresult2, xdata, ydata );
grid on
xlabel('H')
ylabel('M')
Ms = fitresult2.Ms
a = fitresult2.A
b = fitresult2.B
k = 0
set (handles.edit2,'String',num2str(a))
set (handles.edit3,'String',num2str(b))
set (handles.edit4,'String',num2str(k))
set (handles.edit5,'String',num2str(Ms))
elseif (popvalue == 4)
[xdata, ydata] = prepareCurveData(t1, t2);
ft = fittype( 'Ms*(1-B/x^2)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
[fitresult3, gof3] = fit( xdata, ydata, ft, opts );
plot( fitresult3, xdata, ydata );
grid on
xlabel('H')
ylabel('M')
Ms = fitresult3.Ms
a = 0
b = fitresult3.B
k = 0
set (handles.edit2,'String',num2str(a))
set (handles.edit3,'String',num2str(b))
set (handles.edit4,'String',num2str(k))
set (handles.edit5,'String',num2str(Ms))
end

Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2021a

Asked:

on 23 Apr 2021

Edited:

on 23 Apr 2021

Community Treasure Hunt

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

Start Hunting!