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.
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!