フィルターのクリア

How to add values in a column of a uitable?

1 回表示 (過去 30 日間)
Sai
Sai 2015 年 4 月 14 日
コメント済み: Sai 2015 年 4 月 14 日
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 Center および File ExchangeScope Variables and Generate Names についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by