フィルターのクリア

How to add cells in a uitable?

5 ビュー (過去 30 日間)
Sai
Sai 2015 年 4 月 17 日
編集済み: Cindy Solomon 2015 年 4 月 21 日
I want to add cells in the third column of my uitable. The values displayed in the uitable are coded as such. This is for Beef Teriyaki and all the other items are coded in similar fashion.
% code
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);
How would I add the third column 'Price' to get the total price and display it in the last row? I have tried this code.
% code
tot=get(handles.uitable1,'Data');
totn=sum(tot{:,3});
tot(8,3)=totn;
set(handles.uitable1,'Data',tot);
The says error using sum. ' Too many input arguments'
Thanks in advance!

回答 (1 件)

Cindy Solomon
Cindy Solomon 2015 年 4 月 21 日
編集済み: Cindy Solomon 2015 年 4 月 21 日
Hi Sai,
Since your table is a cell array, you would first need to convert your "tot" to an array to execute "sum" on it. For example, instead of doing:
sum(tot{:,3})
it is easiest to do this in 2 steps. Specifically:
totArray = [tot{:,3}]
totN = sum(totArray)
This is because "sum" does not take comma separated lists as an input, which is what tot{:.3} would return. Hope this helps!

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by