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

擷取.PNG
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

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!
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};
Thank you very much !!
But, I don't understand about your default function.
d = {'Male',52,true;'Male',40,true;'Female',25,false};
What the means of "52" and "true" ?
My English is not well ,hope you can know what my mean.
Thank you :)
By the way ,the first part of code is esay to understand!
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.
Unless your table is editable, in which case you will need something fancier to bring back the other column next time.

Sign in to comment.

Answers (1)

Categories

Asked:

on 1 Oct 2019

Answered:

on 7 Oct 2019

Community Treasure Hunt

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

Start Hunting!