GUI to plot excel with a next and previous button

I am a newbie working on a simple GUI that has three components:
  • axes to show the plot (tag: plotty)
  • next button (tag: NextButton)
  • previous button (tag: PreviousButton)
What I want to do is to make the GUI load data from each excel files and make the plot to display in axes. When user presses the next button, the plot will be updated with the data from the next available excel.
I made some changes to my code according to the comments and it is now working. Thank you Geoff!

 채택된 답변

Geoff Hayes
Geoff Hayes 2016년 7월 26일
chlor - if, in your OpeningFcn you define local variables as you have done as
function next_previous_in_plotty_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
filelist = {'1.xls', '2.xls', '3.xls', '4.xls'}
i = 1;
k = length(filelist);
then filelist, i, and k will only be visible within this function and be available for the duration of this function call (since not persistent and this function is only ever called once). If you want this data to be available to other callbacks, then you need to save it to the handles structure as
function next_previous_in_plotty_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.filelist = {'1.xls', '2.xls', '3.xls', '4.xls'}
handles.i = 1;
handles.k = length(file list);
guidata(hObject, handles);
Order is important in the above - we create new fields in the handles struct and then save it using guidata. (Note that you may want to consider renaming the i and k variables to something that gives an idea as to what they represent.)
And you should be able to declare your function wherever you want in the m file. Typically, I do this before I use (or call) the function.

댓글 수: 5

chlor - look at the function signature and the first line for your UpdateAxes function
function UpdateAxes
filelist = get(handles.filelist)
In the second line, you are referencing handles but you aren't passing it as an input. You would need to do
function UpdateAxes(handles)
filelist = get(handles.filelist)
and then pass in handles whenever you call it.
chlor thanks
chlor thanks 2016년 7월 26일
편집: chlor thanks 2016년 7월 26일
Thank you so much for this important piece of info!
I just tried out rewriting all my codes to make sure they follow the format you gave me and they worked! As a newbie this is a nice confidence boost :D
Thank you very much Geoff for all your help to get me started!!
Glad that I was able to help, chlor!
I have been struggling for some couple of days in a lightly similar isssue.But so far, no one has answered my preoccupation.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by