Fitting using pop up menu on matlab gui

조회 수: 2 (최근 30일)
Rafael Ferdinandus
Rafael Ferdinandus 2021년 4월 3일
댓글: VBBV 2021년 4월 3일
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.

채택된 답변

VBBV
VBBV 2021년 4월 3일
편집: VBBV 2021년 4월 3일
%if
file=uigetfile('*.xlsx')
set(handles.edit1,'String', file)
data = xlsread(file)
Try above
  댓글 수: 2
VBBV
VBBV 2021년 4월 3일
Since youre trying to assign the filename to handles structre. The name of file need to be declared in opening function. That's why it throws error
VBBV
VBBV 2021년 4월 3일
Moreover, filename is not a standard GUI component like edit box or check boxes etc. So it needs to be declared before it can be assigned to handles structure

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by