MATLAB Answers

Adding successive cells in a columns

1 ビュー (過去 30 日間)
Isaac Ahenkorah
Isaac Ahenkorah 2020 年 9 月 18 日
回答済み: Isaac Ahenkorah 2020 年 9 月 18 日
Hi,
I have a table (1x7921). I want to add successive columns. For example add column 1:16, 17:32, 32: 48 etc.
Is there a code that I can used to successively add specific range of columns?
  4 件のコメント
Isaac Ahenkorah
Isaac Ahenkorah 2020 年 9 月 18 日
Thanks Walter,
I have removed the non-numeric data in the first row. Also, I have filtered the data and I now have a total of 7920 rows, which will be divisible by 16.
Any suggestion on how to such each group of coloured data?

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 9 月 18 日
sum(reshape(table2array(YourTable), 16, []))
but having a table object with only one row and 7921 variables is not at all common. It would be far more likely that you have a numeric vector, in which case
sum(reshape(YourVector, 16, []))
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 9 月 18 日
Good point. But 7920 is divisible by 16, and the user shows a text entry in the first row, so it is plausibly 7920 rows of numeric values.

サインインしてコメントする。

その他の回答 (2 件)

madhan ravi
madhan ravi 2020 年 9 月 18 日
編集済み: madhan ravi 2020 年 9 月 18 日
Assuming after sir Walter’s comment:
T = TabLe{:, :};
n = numel(TabLe);
t = [TabLe, nan(1, 16 - mod(n, 16))];
Wanted = sum(reshape(t, [], 16), 'omitnan') % nansum() for older versions
  2 件のコメント
madhan ravi
madhan ravi 2020 年 9 月 18 日
Both sir Walter’s answer and my answer should work , once you read the data using readtable()

サインインしてコメントする。


Isaac Ahenkorah
Isaac Ahenkorah 2020 年 9 月 18 日
Thanks Walter and Ravi,
I think both suggestions from you works really well. Much appreciated.
Regards,
Isaac

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by