How to use pop-up menu to control table in GUIDE?
Mostrar comentarios más antiguos

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 comentarios
Ankit
el 1 de Oct. de 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
el 1 de Oct. de 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
el 2 de Oct. de 2019
Walter Roberson
el 2 de Oct. de 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
el 2 de Oct. de 2019
Unless your table is editable, in which case you will need something fancier to bring back the other column next time.
Respuestas (1)
Ankit
el 7 de Oct. de 2019
0 votos
hi chia yu li,
here you can find such GUI.
thanks
Ankit
Categorías
Más información sobre Tables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!