Getting Pop-up menu output as Excel sheet for plotting

1 view (last 30 days)
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 Comments
Varun Kumar
Varun Kumar on 17 May 2019
when i select particular sheet in popup menu for plotting i am not getting plot and getting error as shown.
error.png
Varun Kumar
Varun Kumar on 17 May 2019
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')

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 19 May 2019
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 Comments
Varun Kumar
Varun Kumar on 21 May 2019
Edited: Varun Kumar on 21 May 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
Walter Roberson
Walter Roberson on 21 May 2019
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!