import XLSX FILE and plot it in guide

im trying to import ecxle file in the guide and plot it using one push bottom and 2 popupmene i used this code but it didnt work
handles.fileName=uigetfile('*.xlsx');
guidata(hObject,handles)
setPopupmenuString(handles.popupmenuX,eventdata,handles)
setPopupmenuString(handles.popupmenuY,eventdata,handles)
set(handles.popupmenuX,'callback','@(hObject,eventdata)project(''updateAxes'',hObject,eventdata,guidata(hObject))')
set(handles.popupmenuY,'callback','@(hObject,eventdata)project(''updateAxes'',hObject,eventdata,guidata(hObject))')
function setPopupmenuString(hObject,eventdata,handles)
fileName=handles.fileName;
[numbers,colNames]=xlsread(fileName);
set(hObject,'string',colNames);
function [x,y] = readExcelColumns(fileName,xCol,yCol)
% READEXCELCOLUMNS returns columns from .XLSX file
fileName='data.xlsx';
a=xlsread(fileName);
x=a(:,xCol); % make original Excel column into 'x'
y=a(:,yCol); % make original Excel column into 'y'
function updateAxes(hObject,eventdata,handles)
xColNum=get(handles.popupmenuX,'value');
yColNum=get(handles.popupmenuY,'value');
fileName=handles.fileName;
[x,y] = readExcelColumns(fileName,xCol,yCol);
plot (handles.axes8,x,y)

6 comentarios

Rik
Rik el 15 de Abr. de 2019
You are overwriting the file name. Is that intentional?
Once that works you should put in some checks to confirm a file has been selected.
ROWEDAH HUSSIEN
ROWEDAH HUSSIEN el 18 de Abr. de 2019
no its not but that the codr i found for this purpose
do youhave a simple code?
Rik
Rik el 18 de Abr. de 2019
I don't really understand what you mean, but I suspect you need to replace this:
function [x,y] = readExcelColumns(fileName,xCol,yCol)
% READEXCELCOLUMNS returns columns from .XLSX file
fileName='data.xlsx';
a=xlsread(fileName);
x=a(:,xCol); % make original Excel column into 'x'
y=a(:,yCol); % make original Excel column into 'y'
with this:
function [x,y] = readExcelColumns(fileName,xCol,yCol)
% READEXCELCOLUMNS returns columns from .XLSX file
a=xlsread(fileName);
x=a(:,xCol); % make original Excel column into 'x'
y=a(:,yCol); % make original Excel column into 'y'
ROWEDAH HUSSIEN
ROWEDAH HUSSIEN el 18 de Abr. de 2019
thanks for replay but it didnt work
do you have different code from this one to read excel file and plot it in gui
Rik
Rik el 18 de Abr. de 2019
"it didn't work"
There is a lot you can do with Matlab, but the mind reading toolbox is still in development. You need to explain what went wrong. What errors are you getting? Have you tried to use the debugging tools to find out at what line in your code the results are different from what you expect?
ROWEDAH HUSSIEN
ROWEDAH HUSSIEN el 18 de Abr. de 2019
the proble it run but the output not plot but its the is that
@(hObject,eventdata)project('updateAxes',hObject,eventdata,guidata(hObject))
Untitled.png

Iniciar sesión para comentar.

Respuestas (1)

Rik
Rik el 18 de Abr. de 2019
Now I realize what was the strange thing about your code: they are char arrays instead of function handles. In principle that is fine, but it has the effect of calling eval on that array, which doesn't run the function, but creates the handle you're seeing.
Your function doesn't actually ever run. The code below should fix this.
set(handles.popupmenuX,'callback',@(hObject,eventdata)project('updateAxes',hObject,eventdata,guidata(hObject)))
set(handles.popupmenuY,'callback',@(hObject,eventdata)project('updateAxes',hObject,eventdata,guidata(hObject)))

3 comentarios

ROWEDAH HUSSIEN
ROWEDAH HUSSIEN el 19 de Abr. de 2019
there is still error
Error in project>@(hObject,eventdata)project('updateAxes',hObject,eventdata,guidata(hObject)) (line 360)
set(handles.popupmenuY,'callback',@(hObject,eventdata)project('updateAxes',hObject,eventdata,guidata(hObject)))
Walter Roberson
Walter Roberson el 19 de Abr. de 2019
Editada: Walter Roberson el 19 de Abr. de 2019
Is there more detail about the error? For example, does it say that guidata is an unknown function or variable ?
Where are you storing something into handles.fileName ?
ROWEDAH HUSSIEN
ROWEDAH HUSSIEN el 19 de Abr. de 2019
yes im getting this error
Undefined function or variable 'xCol'.
Error in project>updateAxes (line 375)
[x,y] = readExcelColumns(fileName,xCol,yCol);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in project (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in project>@(hObject,eventdata)project('updateAxes',hObject,eventdata,guidata(hObject)) (line 360)
set(handles.popupmenuY,'callback',@(hObject,eventdata)project('updateAxes',hObject,eventdata,guidata(hObject)))
Error while evaluating UIControl Callback.

Iniciar sesión para comentar.

Preguntada:

el 14 de Abr. de 2019

Editada:

el 19 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by