data from uitable GUI

Hello everyone,
For give me for this question, i am a bit new at matlab
i have a code that uses a pushbutton to insert 2 values on a uitable, then, when i have the values on the table, i press another pushbutton to make some formula and then display it on another statictext, like shown bellow:
function testetabela_OpeningFcn(hObject, eventdata, handles, varargin) %%% Clear the table
dados=get(handles.uitable1,'Data');
dados(:,:) = [];
set(handles.uitable1,'Data',dados);
handles.output = hObject;
guidata(hObject, handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pushbutton1_Callback(hObject, eventdata, handles) %%% MULTIPLY 2x Edittext and obtain c
a=str2double(get(handles.edit1,'String'));
b=str2double(get(handles.edit2,'String'));
c=a*b;
set(handles.edit3,'String',c);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pushbutton2_Callback(hObject, eventdata, handles) %%% SET C value and B value ON THE TABLE
g=str2double(get(handles.edit2,'String'));
j=str2double(get(handles.edit3,'String'));
dados=get(handles.uitable1,'Data');
if isempty(dados)
dados{1,1}=j;
dados{1,2}=g;
else
dados{end+1,1}=j;
dados{end,2}=g;
end
set(handles.uitable1,'Data',dados)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pushbutton3_Callback(hObject, eventdata, handles) %In this button i would like to get just the fields that have values on the table
% and ignore the cells that have nothing.
%
dados=get(handles.uitable1,'Data');
da1=dados{1,1};
da2=dados{2,1};
da3=dados{3,1};
da4=dados{4,1};
da5=dados{5,1};
da6=dados{6,1};
az1=dados{1,2};
az2=dados{2,2};
az3=dados{3,2};
az4=dados{4,2};
az5=dados{5,2};
az6=dados{6,2};
A=da1+da2+da3+da4+da5+da6+az1+az2+az3+az4+az5+az6;
set(handles.text2,'String',A)
I just can obtain the A value when all cells are with data, why? How can i obtain A just for cells that have data?
It gives to me this error: "Index exceeds matrix dimensions."
Thanks.

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by