Fitting using pop up menu on matlab gui
Afficher commentaires plus anciens
i'm new in Matlab and i want to fit equations using popupmenu button on matlab gui, but i still can't work for it.
this is the code i've been working on. let's say i want to get file from an excel format file using this
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.filename=uigetfile('*.xlsx');
filename=handles.filename;
set(handles.edit1,'String', filename)
data = xlsread(filename)
axes(handles.axes1)
t1 = data(:,1)
t2 = data(:,2)
plot(handles.axes1,t1,t2)
grid on
and then i use an excel file to fit equations with popup menu
popvalue = get(handles.popupmenu1, 'value')
data = xlsread(filename)
t1 = data(:,1)
t2 = data(:,2)
if (popvalue == 2)
[xdata, ydata] = prepareCurveData(t1,t2)
ft = fittype( 'Ms*(1-A/x-B/x^2)+(D*x)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
[fitresult{2}, gof(2)] = fit( xData, yData, ft, opts );
plot( handles.axes1, fitresult{2}, t1, t2 );
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';
[fitresult{3}, gof(3)] = fit( xData, yData, ft, opts );
plot( handles.axes1, fitresult{3}, xData, yData );
elseif (popvalue == 4)
ft = fittype( 'Ms*(1-A/x-B/x^2)+(D*x)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
end
and this an error log i get
Unrecognized function or variable 'filename'.
Error in testskripsi>popupmenu1_Callback (line 85)
data = xlsread(filename)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in testskripsi (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)testskripsi('popupmenu1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spline Postprocessing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!