Borrar filtros
Borrar filtros

How to add values in a column of a uitable?

1 visualización (últimos 30 días)
Sai
Sai el 14 de Abr. de 2015
Comentada: Sai el 14 de Abr. de 2015
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!

Respuestas (1)

Jan
Jan el 14 de Abr. de 2015
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 comentario
Sai
Sai el 14 de Abr. de 2015
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

Iniciar sesión para comentar.

Categorías

Más información sobre Scope Variables and Generate Names en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by