how to upload a random excel file and read it
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Sylvain
el 20 de Feb. de 2020
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
1 comentario
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!