How to use pop-up menu to control table in GUIDE?
Show older comments

My pop-up menu has 3 options, ex:Select(Value:1)、A(Value:2)、B(Value:3)
I want to know how to change the table when i choose the "A" or "B"
For example
When I choose "A",I want the table only display the column "date" and "A".
When I choose "B",I want the table only display the column "date" and "B".
I really want to know how to do that :(
Thanks everyone!
6 Comments
Ankit
on 1 Oct 2019
It is possible to do that! What you have done so far? Where are you specifically facing problem? Just to give you a hint :)
if strcmp(selectedOption,'A') % user select option A
myData = get(handles.uitable1,'data');
newData = myData(:,1:2); % selecting date and A column
set(handles.uitable1,'data',newData)
else % in case user select the option B
myData = get(handles.uitable1,'data');
newData = myData(:,[1,3]); % selecting date and column B
set(handles.uitable1,'data',newData)
end
All the Best!
Adam
on 1 Oct 2019
Beware that the above code would only work once though. After that you have thrown away one of the columns of your table permanently so the next time you make a selection it won't work.
@Adam Yes you are right thats why I created a function default which has the table data.
The original code look like this:
function popupmenu1_Callback(hObject, eventdata, handles)
d = default;
set(handles.uitable1,'Data',d);
str = get(handles.popupmenu1,'string');
idx = get(handles.popupmenu1,'value');
selectedOption = str(idx);
if strcmp(selectedOption,'A')
mydata = get(handles.uitable1,'data');
newdata = mydata(:,1:2);
set(handles.uitable1,'data',newdata)
else
mydata = get(handles.uitable1,'data');
newdata = mydata(:,[1,3]);
set(handles.uitable1,'data',newdata)
end
default function:
function d = default
d = {'Male',52,true;'Male',40,true;'Female',25,false};
Chia Yu li
on 2 Oct 2019
Walter Roberson
on 2 Oct 2019
d = {'Male',52,true;'Male',40,true;'Female',25,false};
is made-up input data that Ankit created as example data.
You would replace Ankit's default function with code that returned that cell array of dates and A and B columns that you posted.
Adam
on 2 Oct 2019
Unless your table is editable, in which case you will need something fancier to bring back the other column next time.
Answers (1)
Ankit
on 7 Oct 2019
0 votes
hi chia yu li,
here you can find such GUI.
thanks
Ankit
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!