i want to calculate the maximum of vectors éléments and its position using the diff command, can any one help me ?

2 件のコメント

John D'Errico
John D'Errico 2018 年 11 月 29 日
Why not just use max? Since it does exactly what you claim to want.
diff as applied to a vector will not help you here.
diadalina
diadalina 2018 年 11 月 29 日
it is another way to calculate the max ?

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

 採用された回答

madhan ravi
madhan ravi 2018 年 11 月 29 日

1 投票

[value,index]=max(vector) %use max which does exactly what you want

7 件のコメント

diadalina
diadalina 2018 年 11 月 29 日
編集済み: diadalina 2018 年 11 月 29 日
thank you madhan ravi for your answer but i want with diff, if you can help me , thank you.
Jan
Jan 2018 年 11 月 29 日
@diadalina: Accepting an answer means, that the problem is solved.
The diff command is not useful to find the maximum value.
diadalina
diadalina 2018 年 11 月 29 日
no, it is, when we calculate the sign of the difference between two successive numbers.
madhan ravi
madhan ravi 2018 年 11 月 29 日
編集済み: madhan ravi 2018 年 11 月 29 日
Anytime :) @diadalina , thank you Jan
But it depends upon the monotonicity of the vector also so like John and Jan suggests it's not useful
diadalina
diadalina 2018 年 11 月 30 日
mr ravi what do you want to say by the monotonicity of the vector can you more explain to me please ?
Jan
Jan 2018 年 12 月 3 日
編集済み: Jan 2018 年 12 月 3 日
@diadaline: Use these three inputs:
a = rand(1, 10)
b = 1:10
c = 10:-1:1
While using max() is easy here, there is no chance to use diff() to find a maximum value. But here, diff can be useful:
d = sin(0:0.001:pi)
Here you have the additional knowledge, that the elements are monotonically increasing and decreasing. Together with this knowledge diff can be used:
find(diff(d) <= 0, 1, 'first')
max() is more useful, because it works in the general case also.
diadalina
diadalina 2018 年 12 月 4 日
thank you mr Jan, now it is clear for me.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDiscrete Math についてさらに検索

タグ

質問済み:

2018 年 11 月 29 日

編集済み:

2018 年 12 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by