Listbox and Pushbutton in GUI
Ältere Kommentare anzeigen
I have a listbox(tag:listbox) that gives different choices of plotting(axes tag:plotty), and a pushbutton(tag: NextButton) called "next" which execute the choice that the listbox made. My code in GUI looks something like this:
%some code
handles.i = 1;
handles.k = length(files);
handles.files = files;
guidata(hObject, handles);
% --- Executes on selection change in plotbox.
function listbox_Callback(hObject, eventdata, handles)
files = handles.files;
i=handles.i;
axes(handles.plotty);
listbox_index=get(hObject, 'Value');
switch listbox_index
case 1
[data,~,~] = xlsread(files{i});
x = 1:6;
plot(x, data(1:end))
case 2
[data,~,~] = xlsread(files{i});
x = 2:7;
plot(x, data(1:end))
case 3
[data,~,~] = xlsread(files{i});
x = 4:9;
plot(x, data(1:end))
end
% --- Executes on button press in NextButton.
function NextButton_Callback(hObject, eventdata, handles)
%some code
guidata(hObject, handles)
After some fig test run, the GUI is able to run but not correctly---it seems that my listbox function and pushbutton works separately.
No matter which choice I made in the listbox. The pushbutton automatically execute whats in listbox function case 1, and never goes to case 2 and 3.
I would like to fix the code, any clue is appreciated. Thank you!!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Data Import and Analysis finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!