MATLAB Answers

0

In matlab uitables, Is it possible to add the data in each row together to get its summation? If so, how can i do it?

I created the table using guide.
i have a 7x3 table and four each row i would like to add the data in the first 2 columns so that the summation will go in the third column.
I can i program this feature
any suggestions or examples relevant will help
thanks,
Cordelle

  댓글 수: 0

로그인 to comment.

태그

답변 수: 1

Walter Roberson 님의 답변 5 Jul 2013
 채택된 답변

datacell = get(handles.YourTable, 'Data');
datamatrix = cell2mat(datacell(:,1:end-1));
sums = sum(datamatrix, 2);
sumscell = num2cell(sums);
datacell(:,end) = sumscell;
set(handles.YourTable, 'Data', datacell);

  댓글 수: 3

cell2mat is concatenating the data in the cell array and is distorting my result, for example,
datacell =
'1' '2' ''
'3' '4' ''
'5' '6' ''
'7' '8' ''
and
datamatrix =
12
34
56
78
and the summation of the rows were
sums =
99
103
107
111
and they are suppose to be:
sums =
3
7
11
15
do you know how i can go about fixing my problem?
It seems as if it was adding the ASCII numbers together.
Nevermind, i fixed it, i used:
result = reshape(str2num(datamatrix(:)), size(datamatrix));
to convert number character array to a number integer array. Once that was done, sums = sum(result,2) worked just fine.

로그인 to comment.



Translated by