POPMENU cb1 and IUTABLE: UITB1

1 I have: POPMENU cb1 and IUTABLE: UITB1
in the object POPMENU desire to click each option and need the object IUTABLE is full.
Each option object POPMENU a different data in IUTABLE. (Data: Data1, Data2, Data3)

2 Comments

Dany - please clarify what you need help with. Are you just trying to populate the table with data that is dependent upon the item selected in the popup menu?
YES, IN MENU HAS 3 OPTIONS FOR EACH OPTION THE "uitable" OBJECT IS FILLED WITH A DIFFERENT DATA

Sign in to comment.

Answers (1)

Dany - if you want to fill the uitable with a different set of data given the selection in the popup menu, then you will need to create a callback for the popup menu and have it respond to the user selection. Something like
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% get the index of the selected value (from the menu: 1, 2, or 3)
selectionId = get(hObject,'Value');
% populate the table with a different set of data depending upon the selection
switch selectionId
case 1
set(handles.uitable1,'Data',1*ones(4,4));
case 2
set(handles.uitable1,'Data',2*ones(5,5));
case 3
set(handles.uitable1,'Data',3*ones(6,6));
end
Note how we use use handles to update the uitable (named uitable1). The above is just a simple example which you should be able to fit for your needs. Try it and see what happens!

5 Comments

Thanks a lot Geoff. I have a data with 3 attributes, in the following path load ('C:\data.mat'); I can not load the data. Where I should put the code?
Dany - the code to load the file would be in the pop up menu callback. What do you mean by can not load the data? Are you observing an error or some other problem?
Data loading is not possible to uitable. Doesn't recognize the data "data" in the workspace
function cb1_Callback(hObject, eventdata, handles)
load ('C:\data.mat','data1','data2,'data3');
selectionId = get(hObject,'Value');
switch selectionId
case 1
set(handles.uitb1,'Data',data1,'ColumnNane',colummname);
case 2
set(handles.uitb1,'Data',data2,'ColumnNane',colummname);
case 3
set(handles.uitb1,'Data',data3,'ColumnNane',colummname);
end
Error
Undefined function or variable "data1".
Error in Myfig>cb1_Callback (line 87)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Myfig (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata) Myfig
('cb1_Callback',hObject,eventdata,guidata(hObject))
Dany - there are a handful of bugs in the above code. The line
load ('C:\data.mat','data1','data2,'data3');
is missing a single quote around data2 and so should be replaced with
load ('C:\data.mat','data1','data2','data3');
The local variable colummname is undefined, and the property 'ColumnNane' is incorrect and should be 'ColumnName'.
I was able to create a simple example that is very similar to yours, and I can load the uitable. Please make the above corrections and try again. Also, put a breakpoint in the cb1_callback and step through the code to see what the problem might be.
Geoff Hayes thanks a lot

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Tags

Asked:

on 29 Jan 2015

Commented:

on 4 Feb 2015

Community Treasure Hunt

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

Start Hunting!