How to add values in a column of a uitable?

2 次查看(过去 30 天)
Hey guys! Im looking to add my price values in column 3 and display in in the next row under the same column. Like a total of all items. I've tried using 'sum' function but its considering 'sum' as a variable instead. Please help me out! Thank you!

回答(1 个)

Jan
Jan 2015-4-14
sum is considered as a variable only if you have created a variable with this name before. So remove the line, which creates "sum" as a variable and restart the code.
It is more useful if you post the relevant part of the code, because there is no connection between the graphic output and the problem.
  1 个评论
Sai
Sai 2015-4-14
This is the code i used to display the info in the uitable.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
qty1 = get(handles.edit1,'String');
qty1n = str2num(qty1);
chkprice = 6.95*qty1n;
DAT = num2cell(chkprice);
pr=get(handles.uitable1,'Data');
pr(1,3)=DAT
pr(1,1)={'Chicken Teriyaki'}
pr(1,2)=num2cell(qty1n);
set(handles.uitable1,'Data',pr);
Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
qty2 = get(handles.edit2,'String');
qty2n = str2num(qty2);
beefprice = 7.95*qty2n;
DAT1 = num2cell(beefprice);
br=get(handles.uitable1,'Data');
br(2,3)=DAT1
br(2,1)={'Beef Teriyaki'}
br(2,2)=num2cell(qty2n);
set(handles.uitable1,'Data',br);
Im also trying to figure out how I can automatically display in the next free available row instead of what i did, i.e. br(2,3), predefined where it should display

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by