フィルターのクリア

For example, I want to get a result like this. b=[1 diff(3)]=[1 0]. Not b=[1] .

1 回表示 (過去 30 日間)
Jonghun
Jonghun 2013 年 7 月 30 日
differentiation of constant value is zero. But in matlab, diff(3)=[]; I want to get a vector which components are constant and zero. For example, I want to get a result like this. b=[1 diff(3)]=[1 0]. Not b=[1] How can I solve it?
  1 件のコメント
Iain
Iain 2013 年 7 月 30 日
What else can "3" be? - I mean can it be a vector or what?

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

採用された回答

David Sanchez
David Sanchez 2013 年 7 月 30 日
Do something like the following function:
function out=my_diff(in)
out = diff(in);
if isempty(out)
out = 0;
end

その他の回答 (1 件)

Jan
Jan 2013 年 7 月 30 日
編集済み: Jan 2013 年 7 月 30 日
diff() is not the "differentiation", but the "difference" of neighboring elements. As long as [3] does not have neighboring elements the result is empty, of course.
The "differentiation" is performed by the command gradient. But even with this [3] is not a well defined input: There is no slope between one point. Replying 0 is mathematically incorrect then.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by