Fitting using pop up menu on matlab gui

9 Ansichten (letzte 30 Tage)
Rafael Ferdinandus
Rafael Ferdinandus am 3 Apr. 2021
Kommentiert: VBBV am 3 Apr. 2021
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.

Akzeptierte Antwort

VBBV
VBBV am 3 Apr. 2021
Bearbeitet: VBBV am 3 Apr. 2021
%if
file=uigetfile('*.xlsx')
set(handles.edit1,'String', file)
data = xlsread(file)
Try above
  2 Kommentare
VBBV
VBBV am 3 Apr. 2021
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 am 3 Apr. 2021
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Spline Postprocessing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by