matlab - GUI won't run correct unless radio buttons are cycled through -
i've created gui estimates materials , pricing involved in building home given few criteria provided in ui panels radio buttons options. problem hitting go button gui throws errors unless radio buttons played first. cannot leave buttons on selection when gui run. how can run .m file , hit go on .fig without having touch (aside filling in square footage edit box)?
function uibuttongroup3_selectionchangedfcn(hobject, eventdata, handles) % hobject handle selected object in uibuttongroup3 % eventdata reserved - defined in future version of matlab % handles structure handles , user data (see guidata) tag = eventdata.newvalue; switch get(tag,'tag') case 'onehalfbath' bathroom = 1 case 'twohalfbath' bathroom = 2 case 'threehalfbath' bathroom = 3 end; if bathroom == 1 bathwall = 30 bathsq = 36 elseif bathroom == 2 bathwall = 48 bathsq = 72 elseif bathroom == 3 bathwall = 66 bathsq = 108 end; setappdata(handles.uibuttongroup3,'bathwall',bathwall); setappdata(handles.uibuttongroup3,'bathsq',bathsq); setappdata(handles.uibuttongroup3,'bathroom',bathroom);
the above 1 of 4 ui panels radio buttons, example. written same way. snippets of go button callback below.
function gobut_callback(hobject, eventdata, handles) % hobject handle gobut (see gcbo) % eventdata reserved - defined in future version of matlab % handles structure handles , user data (see guidata) run('urlprice.m'); bathroom = getappdata(handles.uibuttongroup3,'bathroom'); bathsq = getappdata(handles.uibuttongroup3,'bathsq'); bathwall = getappdata(handles.uibuttongroup3,'bathwall'); % floor = get(handles.floor,'value') homename = get(handles.homename,'string'); base = get(handles.basesqft, 'string'); basesqft = str2num(base); totsqft = basesqft .* floor; perim = (((basesqft .^ .5) .* 4) .* floor); perim2 = (basesqft .^ .5) .*4; perim3 = (basesqft .^ .5); walllnft_01 = perim + (bedwall .* 2) + (bathwall .* 2); % double side wall walllnft_02 = perim + bedwall + bathwall; % 1 side wall intdoor = (bedroom .* 2) + (bathroom) + 2; tile = ceil(bathsq/17.44287); thinset = bathroom + 1; index of element remove exceeds matrix dimensions.
the error messages:
index of element remove exceeds matrix dimensions. error in cur2str (line 75) t(1,:) = []; error in homebuilding>gobut_callback (line 267) estmat = cur2str(estmat1,2); error in gui_mainfcn (line 95) feval(varargin{:}); error in homebuilding (line 42) gui_mainfcn(gui_state, varargin{:}); error in @(hobject,eventdata)homebuilding('gobut_callback',hobject,eventdata,guidata(hobject)) error while evaluating uicontrol callback
you use setappdata
store variables later use in uibuttongroup3_selectionchangedfcn
. problem done in function. means the variables not stored until uibuttongroup3_selectionchangedfcn
called, happens when radio buttons played said.
when gui opens, variables not defined yet. therefore should define 3 variables in openingfcn
default value, or make sure user set buttons before hitting go.