How to Subtract and Add across columns in Matlab?

2 ビュー (過去 30 日間)
Minjun Seo
Minjun Seo 2019 年 8 月 13 日
コメント済み: Star Strider 2019 年 8 月 14 日
Okay, I have a data table.
I want to perform simple mathematical operations on the columns of the table versus let's say a different column.
Similar to diff() but diff() works going down the column. I want to know a way to go across.

採用された回答

Star Strider
Star Strider 2019 年 8 月 14 日
編集済み: Star Strider 2019 年 8 月 14 日
In the documentation for diff, see Differences Between Matrix Columns. You need to specify the dimension.
EDIT —
With respect to adding, cumsum (and sum) work the same way. See: Cumulative Sum of Each Row In Matrix.
  2 件のコメント
Minjun Seo
Minjun Seo 2019 年 8 月 14 日
It says that diff is an undefined function for type 'table'. Is there a way to fix this?
Star Strider
Star Strider 2019 年 8 月 14 日
I thought you were actually working with matrices.
Neither diff nor cumsum will work on tables, even using the rowfun function.
You would need to use the table2array function to extract the data from the table, do the calculations, then create a new table with the results.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by