Hello everyone,
I have this code that writes zeros to a matrix based on the length of a listbox and popupmenu options. 1s are written to the matrix based on selections from the popupmenu and listbox:
function [] = pop_ex() % Help goes here.
S.fh = figure('units','pixels',... 'position',[200 400 320 340],... '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'}); 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'))); %create matrix A, fill with zeros based on length of popup and list items
A(get(S.pp,'val'),get(S.ls,'val')) = 1; %write 1s for selected items
A %output A
The code works however, I want to append the matrix instead of creating a new one each time.
Best Answer