Effacer les filtres
Effacer les filtres

How to add cells in a uitable?

5 vues (au cours des 30 derniers jours)
Sai
Sai le 17 Avr 2015
Modifié(e) : Cindy Solomon le 21 Avr 2015
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!

Réponses (1)

Cindy Solomon
Cindy Solomon le 21 Avr 2015
Modifié(e) : Cindy Solomon le 21 Avr 2015
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!

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by