how to upload a random excel file and read it
조회 수: 2 (최근 30일)
이전 댓글 표시
I am working on an assignment in which i want to develope a stand alone app (GUI) of curve fitting.
in which i need to get data input from a random excel file,and read that file to make a graph.
under 'upload file'i wrote this fuction
function pushbutton2_Callback(hObject, eventdata, handles)
a= uigetfile({'*.xlsx'},'select the excel file');
b=xlsread('a);
under 'calculate' i wrote this fuction
function pushbutton1_Callback(hObject, eventdata, handles)
x=dataset(:,1);
y=dataset(:,2);
p=polyfit(x,y,5);
xp=0:0.1:0.5;
yp=polyval(p,xp);
plot(x,y,'--',xp,yp);
grid;
-- its not working,i want matlab to open a 'select window' so a user can upload a rondom excel file(which contain data),and when the user click the 'calculate button' it will fit the curve.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/272573/image.png)
댓글 수: 0
답변 (1개)
Sylvain
2020년 2월 20일
The trick is that your functions have local variables, you need to send them out using the handles.
you may use the import data toolbox , and generate an import function.
before generating a function, template the out put
generate the code importfile.m and modify it so that your function is
function out = importfile(filename)
...
end
then use this function in your upload file button call back:
function pushbutton2_Callback(hObject, eventdata, handles)
a= uigetfile({'*.xlsx'},'select the excel file');
b = importfile(filename);
handles.dataset = b;
guidata(hObject, handles);
end
now use the handles to retrieve the data and plot the results
function pushbutton1_Callback(hObject, eventdata, handles)
x=handles.dataset(:,1);
y=handles.dataset(:,2);
p=polyfit(x,y,5);
xp=0:0.1:0.5;
yp=polyval(p,xp);
plot(x,y,'--',xp,yp);
grid;
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!