MATLAB Answers

Lorenzo
0

GUIDE: Updating table rows depending on popup user choice

Lorenzo
さんによって質問されました 2013 年 6 月 26 日
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!

  0 件のコメント

サインイン to comment.

3 件の回答

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

  0 件のコメント

サインイン to comment.


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
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.

サインイン to comment.


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
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...

サインイン to comment.



Translated by