MATLAB: Problem with Cell Arrays in GUIDE

cell arraysguide

I am attempting to fill a cell array as follows: CellArray(1,50)={zeros(M,N)} With M being popupmenu options and N being listbox options.
so far I have this code which does work to a certain extent. It takes listbox options and popupmenu options and stores them into array. popupmenu options are columns and listbox options are rows. I am attempting to use a for loop to store the currently selected items into my cell array, Z:
R = get(handles.popupmenu1,'val');
%listbox accepts multiple selections*
C = get(handles.listbox1,'val');
A = zeros(length(get(handles.popupmenu1,'string')),length(get(handles.listbox1,'string')));
I = sub2ind(size(A),[R repmat(R,1,length(C))],[1 C]);
Z = cell(1,50);
for i = 1: 50
Z(:) = {I}
end
The only problem is that it saves all of the listbox options and all of the popupmenu options instead of just the currently selected items. But it does store the array A into the 1 x 50 cell array Z so I guess its a start. So the question is how would i need to modify this code in order to into my 1 by 50 cell array?
Here is what the output looks like:
Z =
Columns 1 through 7
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 8 through 14
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 15 through 21
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 22 through 28
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 29 through 35
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 36 through 42
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Columns 43 through 49
[1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double] [1x7 double]
Column 50
[1x7 double]

Best Answer

O.k., So now I will make another simple example. You tell me if we are finally on the same page ;-)! This example fills a 1-by-3 cell instead of a 1-by-50. You can modify it for your needs.
function [] = pop_ex()
% Help goes here.
S.fh = figure('units','pixels',...
'position',[100 300 120 140],...
'menubar','none',...
'name','slider_ex',...
'numbertitle','off',...
'resize','off');
S.pp = uicontrol('style','pop',...
'unit','pix',...
'position',[20 20 80 40],...
'string',{'one','two','three','four'},...
'callback',@pp_call);
S.ls = uicontrol('style','list',...
'unit','pix',...
'position',[20 80 80 40],...
'min',0,'max',5,...
'string',{'lone','ltwo','lthree','lfour','lfive','lsix'});
S.C = cell(1,3);
S.cnt = 1;guidata(S.fh,S)
function [] = pp_call(varargin)
% Callback for the popup.
S = guidata(gcbf);
A = zeros(length(get(S.pp,'string')),length(get(S.ls,'string')));
A(get(S.pp,'val'),get(S.ls,'val')) = 1;
S.C(S.cnt) = {A}; % Update this particular element of the cell.
S.cnt = S.cnt + 1; % Increment the counter.
guidata(S.fh,S) % Resave the structure so updates are not lost.
S.C{:} % Show in the command window.