How to Subtract and Add across columns in Matlab?
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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
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 Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!