Fitting using pop up menu on matlab gui
显示 更早的评论
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.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!