1-d gradient

15 ビュー (過去 30 日間)
Yostena Wassef
Yostena Wassef 2018 年 12 月 17 日
編集済み: Jan 2018 年 12 月 17 日
can i use covlution to get the same result of 1-d gradient
Screenshot (58).png
Screenshot (59).png
  1 件のコメント
KSSV
KSSV 2018 年 12 月 17 日
Read about Taylor Series.

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

採用された回答

Jan
Jan 2018 年 12 月 17 日
Your question contains the answer already. If the data is a vector, conv is sufficient instead of conv2:
x = rand(1, 10)
dx_1 = gradient(x)
dx_2 = conv(x, [0.5, 0, -0.5], 'same')
The first and last element of dx_2 differ from dx_1, but you can adjust it with the one-sided quotient of differences easily.
  2 件のコメント
Yostena Wassef
Yostena Wassef 2018 年 12 月 17 日
input is matrix
so i can't get the same result for 1dgradient
Jan
Jan 2018 年 12 月 17 日
編集済み: Jan 2018 年 12 月 17 日
Then the screenshot of the text "When F is a vector" is simply confusing. Please ask the questions as clear as possible.
dx_2 = conv2(x, [0.5, 0, -0.5], 'same')
This replies the same as gradient, except for the first and last column. Then:
dx_2(:, 1) = diff(x(:, 1:2), 1, 2);
dx_2(:, end) = diff(x(:, end-1:end), 1, 2);
Or if you love conv2:
d = conv2(x, [1, -1], 'valid');
dx_2(:, 1) = d(:, 1);
dx_2(:, end) = d(:, end);

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by