フィルターのクリア

How to overcome the problem with the function diff used to approximate matrix derivative.

3 ビュー (過去 30 日間)
Nicola Dall'Osto
Nicola Dall'Osto 2022 年 5 月 20 日
回答済み: Star Strider 2022 年 5 月 20 日
Hi, I have an issue using diff function to calculate the derivative of a matrix.
Using diff(X), where X is a matrix m x n matrix, I obtain in output a matrix with m-1 rows. The problem is that I need to concatenate the result of the derivative operation with the X matrix along the columns. In other words, I need to obtain a m x 2n matrix where the first n columns are referring to the X matrix and the last n columns are referring to the derivatives of X's columns along the rows.
How can I deal with this problem? Is it rigth to add a row of zeros before applying the diff function or after applying it in order to have the same numebr of rows before concatenating?
  1 件のコメント
Bjorn Gustavsson
Bjorn Gustavsson 2022 年 5 月 20 日
For this you have to decide what your application of this requires. What are you trying to achieve? what will you use that final matrix for? Maybe you can use what you suggested, maybe you could use the gradient function instead and have central differences in the main part and single-sided differences along the edge. Only you can decide, since only you know what the use-case is.

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

回答 (1 件)

Star Strider
Star Strider 2022 年 5 月 20 日
Use the gradient function instead of diff.

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by