필터 지우기
필터 지우기

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 CenterFile Exchange에서 Scope 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