GUIDE: Updating table rows depending on popup user choice

1 次查看(过去 30 天)
Dear all; this is the first time I'm using guide so this may be a really stupid question, sorry about that!
I have a popup and a table. Depending on what's the user choice in the popup, the RowName properties for the table changes. Once I'll have managed this one, then I need to add a second set of table+ popup and do exactly the same thing.
How would you accomplish that? I'm having troubles with this especially because of the nested functions I guess....
Thanks everybody!

采纳的回答

Tom
Tom 2013-6-26
Set this for the popupmenu callback.
In the CreateFcn callback of the popupmenu, you can add some options, e.g.
set(hObject,'String',{'Option 1','Option 2'})
In the Callback of the popupmenu you can then change the table's row names based on the popupmenu selection:
val = get(hObject,'Value');
if val == 1
set(handles.uitable1,'RowName',{'One','Two','Three'})
elseif val == 2
set(handles.uitable1,'RowName',{'Alpha','Beta','Gamma'})
end

更多回答(2 个)

Lorenzo
Lorenzo 2013-6-26
Great! It works perfectly! I've been fighting with this for the whole day... I guess my problem is that when I built the user interface I edited some stuff by end in the GUI itself (for instance I entered the Option 1','Option 2' you mentioned above in the property editor of the popup menu rather than entering them in the matlab editor) this way I could not change anything from the editor itself... So, to solve this, I had to start everything from scratch again.... Is it supposed to work this way?
Thanks again for your help!
  1 个评论
Tom
Tom 2013-6-26
You can do either - I prefer to edit in the script because I find it easier to see what I've set, and it's easier to change, but that's a personal preference.

请先登录,再进行评论。


Lorenzo
Lorenzo 2013-6-27
Dear all; I need to create more than one popup+list set so it would be good if I could use a variable for the options for the popup and some variables for the RowName option for the lists. Now, I created a variable and I defined that as global but it doesn't seem to be passed to the subfunctions of the popup and the list. So: 1- what's the right way to define this variable? Handle, glabal.... 2- where do I have to define this variable? I tried defining it inside the _OpeningFcn and the _OutputFcn with no luck.
Thanks again!
  1 个评论
Lorenzo
Lorenzo 2013-6-27
Ok, I solved it by declaring my lists as variables in the OpeningFcn, and by declaring them as global. Previously I forgot to declare them as global also within the function where I needed to use them, that's why I could get them to work properly.
Sorry for the silly question...

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by