Getting Pop-up menu output as Excel sheet for plotting

hi everyone,
i am creating a gui which will help to compare the data from two selected sheets of excel file via plotting, excel file consist of various sheets. i am using one pusbutton for importing the excel file and two popup menu button for selection of two desired sheets of excel file and finally one axes to plot the data. my problem is that when i select a particular sheet from popup menu its not getting selected as file.

3 comentarios

Luna
Luna el 16 de Mayo de 2019
Please share your code as .m file or text because it is impossible to run it via screenshot.
when i select particular sheet in popup menu for plotting i am not getting plot and getting error as shown.
error.png
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('*.xls')
guidata(hObject, handles)
setPopupmenuString(handles.popupmenuX, eventdata, handles)
setPopupmenuString(handles.popupmenuY, eventdata, handles)
set(handles.popupmenuX, 'callback', 'sheetstoread2(''updateAxes'',gcbo,[],guidata(gcbo))')
set(handles.popupmenuY, 'callback', 'sheetstoread2(''updateAxes'',gcbo,[],guidata(gcbo))')
function setPopupmenuString(hObject, eventdata, handles)
filename = handles.filename
[~, Sheets] = xlsfinfo(filename)
set(hObject, 'string', Sheets)
function updateAxes(hObject, eventdata, handles)
filename = 'handles.filename.xls'
data1 = get(handles.popupmenuX, 'Value')
data11 = get(handles.popupmenuX, 'String')
data111=xlsread(handles.popupmenuX,' data11')
data2 = get(handles.popupmenuY, 'Value')
data22 = get(handles.popupmenuY, 'String')
data222=xlsread(handles.popupmenuY, 'data22')
a=data111(:,19);
b=data111(:,29);
c=data111(:,32);
d=data111(:,35);
A=data222(:,19);
B=data222(:,29);
C=data222(:,32);
D=data222(:,35);
plot(handles.axes1, a,b,'r',a,c,'g',a,d,'b','MarkerSize',10)
hold on
plot(handles.axes1, A,B,'k',A,C,'m',A,D,'c','MarkerSize',1)
hold off
legend('201-X','201-Y','201-Z','202-X','202-Y','202-Z')

Iniciar sesión para comentar.

 Respuesta aceptada

Varun - I don't understand this line of code
data111=xlsread(handles.popupmenuX,' data11')
Why are you using the handle of the popupmenu (X) as the file name? In your initial code post, you are using a filename field from the handles structure. Why the change? Also, why are you putting data11 in quotes? (Again this differs from your initial code post...)

6 comentarios

hello
i want the slected file from the popup menu will be used for plotting. i dont why i used all those which you mentioned in the comments above i am new to programming, i want to use those files which are selected from popup menu for plotting i dont know how to read those files and use in plotting please help me tahnk you.
Get the String property from the handle. It will be a cell array of character vectors. Get the Value property of the handle. It will be the index of the entry the user chose. Use it to index the cell array. That will be the last part of the file name. Use fullfile to put the directory name on as well.
[~, Sheets1]=xlsfinfo(handles.filename)
set(hObject,'String',Sheets1)
index_selected = get(hObject, 'Value')
file_list=get(hObject, 'String')
selected=file_list{index_selected}
filename=handles.filename
data1=xlsread(filename(selected))
i used this code but getting errror as
Index exceeds matrix dimensions.
Error in sheetstoread5>popupmenu2_Callback (line 131)
data2=xlsread(filename(selected))
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in sheetstoread5 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)sheetstoread5('popupmenu2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Undefined function or variable "data1".
Error in sheetstoread5>pushbutton2_Callback (line 155)
a=data1(:,19);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in sheetstoread5 (line 42)
gui_mainfcn(gui_State, varargin{:});
Varun - from your code
index_selected = get(hObject, 'Value')
file_list=get(hObject, 'String')
selected=file_list{index_selected}
filename=handles.filename
data1=xlsread(filename(selected))
what is selected? Is it a filename (since you are extracting it from the file_list)? In that case, why do you need to do
data1=xlsread(filename(selected))
where filename is (supposedly) a list of filenames? Why can't you just do
data1=xlsread(selected)
instead?
Also, you may want to rename some of your variables to make it more clear what they represent. For example, if selected is a file name that the user has selected, why not name it selectedFilename?
Varun Kumar
Varun Kumar el 21 de Mayo de 2019
Editada: Varun Kumar el 21 de Mayo de 2019
ya i got it thank you so much.
i modified my code as
[~, Sheets2]=xlsfinfo(handles.filename)
set(hObject,'String',Sheets2)
index_selected = get(hObject, 'Value')
sheet_list=get(hObject, 'String')
selectedsheet=sheet_list{index_selected}
filename=handles.filename
data2=xlsread(filename, selectedsheet)
after this i wanted to plot the data using pushbutton callback with code
a=data1(:,19);
b=data1(:,29);
c=data1(:,32);
d=data1(:,35);
A=data2(:,19);
B=data2(:,29);
C=data2(:,32);
D=data2(:,35);
plot(handles.axes1, a,b,'r',a,c,'g',a,d,'b','MarkerSize',10)
hold on
plot(handles.axes1, A,B,'k',A,C,'m',A,D,'c','MarkerSize',1)
hold off
i am getting error as
Undefined function or variable 'a'.
Error in sheetstoread5>pushbutton2_Callback (line 162)
plot(handles.axes1, a,b,'r',a,c,'g',a,d,'b','MarkerSize',10)
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in sheetstoread5 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)sheetstoread5('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
please help me to resolve
I suspect that your
a=data1(:,19);
is not in the same function that
plot(handles.axes1, a,b,'r',a,c,'g',a,d,'b','MarkerSize',10)
is in.
Also, your code
[~, Sheets2]=xlsfinfo(handles.filename)
set(hObject,'String',Sheets2)
index_selected = get(hObject, 'Value')
sheet_list=get(hObject, 'String')
selectedsheet=sheet_list{index_selected}
gets the names of the sheets from xlsinfo, sends it to the the popup string list, and then immediately without giving any time to draw the control or for the user to choose something, asks which value the user chose.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 16 de Mayo de 2019

Comentada:

el 21 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by