How to substract in table

조회 수: 27 (최근 30일)
Dion Theunissen
Dion Theunissen 2021년 6월 24일
댓글: Walter Roberson 2021년 6월 24일
Hi,
How can I substract the first value of all columns from the other rows in a table?
So I have a table like this:
1230764 205775 182354 208200 226372 225378 204289 181576
1230764 205775 182354 208200 226372 225378 204289 181576
1230764 205775 182354 208200 226372 225378 204289 181576
1230766 205775 182354 208200 226372 225378 204289 181576
1230830 205775 182354 208200 226372 225378 204289 181576
1230915 205775 182354 208200 226372 225378 204289 181576
1231113 205780 182357 208205 226375 225380 204291 181581
1242631 207147 183648 209735 227913 226996 205878 183094
1242631 207147 183648 209735 227913 226996 205878 183094
1242631 207147 183648 209735 227913 226996 205878 183094
1242631 207147 183648 209735 227913 226996 205878 183094
1242631 207147 183648 209735 227913 226996 205878 183094
1242631 207147 183648 209735 227913 226996 205878 183094
1242631 207147 183648 209735 227913 226996 205878 183094
1242631 207147 183648 209735 227913 226996 205878 183094
1242631 207147 183648 209735 227913 226996 205878 183094
1242631 207147 183648 209735 227913 226996 205878 183094
1242631 207147 183648 209735 227913 226996 205878 183094
And need to substract 1230764 from the other values of that column and so on for the other columns.
Thanks, Dion
  댓글 수: 1
Dion Theunissen
Dion Theunissen 2021년 6월 24일
After I substract al those value, I want to sum all the rows so i get 1 column of all the values

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2021년 6월 24일
Provided that all variables are numeric:
array2table(T{:,:} - T{1,:}, 'variablenames', T.Properties.VariableNames)
  댓글 수: 2
Walter Roberson
Walter Roberson 2021년 6월 24일
array2table(sum(T{:,:} - T{1,:},1), 'variablenames', T.Properties.VariableNames)
Walter Roberson
Walter Roberson 2021년 6월 24일
To sum along the rows, change the ,1 to ,2

댓글을 달려면 로그인하십시오.


Mohammad Sami
Mohammad Sami 2021년 6월 24일
You can use varfun to subtract the first value in the column from the rest of the values.
out = varfun(@(x)x-[0;repelem(x(1),length(x)-1,1)],mytable);
  댓글 수: 1
Dion Theunissen
Dion Theunissen 2021년 6월 24일
Can I also sum all the values per row on this way?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 ANOVA에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by