I'm trying to create a shopping list using buttons and am having trouble getting my list to stack items.
What I want the program to do:
Click the meal that you want to add to the list --> The button callback f'n adds to the global list --> Click done and the total list of ingredients prints to the command window.
Menu script:
clc, close all
f=figure;
set(f,'userdata',zeros(25,1));
bg_h=uibuttongroup(f, 'title', 'Breakfast', 'units', 'normalized', 'Position', [0 0.5 0.5 0.5]);
bg2_h=uibuttongroup(f, 'title', 'Entrees', 'units', 'normalized', 'Position', [0.5 0.5 .5 0.5]);
bg3_h=uibuttongroup(f, 'title', 'Sides', 'units', 'normalized', 'Position', [0 0 0.5 0.5]);
lg_h=uibuttongroup(f, 'title' ,'List','units','normalized','Position', [0.5 0 0.5 0.5]);
TOTAL=uicontrol(lg_h, 'style', 'listbox', 'units','normalized','Position', [0 0 1 1]);
Oatmeal_h=uicontrol(bg_h, 'style', 'pushbutton', 'string', 'Oatmeal','units', 'normalized','Position', [0 0.85 0.25 0.1], 'callback', address@hidden,TOTAL});
Oatmeal Callback:
function oatmeal_fn(Oatmeal_h, evt, f)
total=get(f,'userdata');
ind=5;
total(ind)=total(ind)+1;
set(f,'userdata',total);
endfunction
The error message I receive is:
>> error: total(5): out of bound 0
execution error in graphics callback function
Does this mean that total is a matrix with no elements? I'm not sure what I'm doing wrong.