フィルターのクリア

ratios from an array

3 ビュー (過去 30 日間)
Dinu Th.
Dinu Th. 2020 年 4 月 20 日
コメント済み: Ameer Hamza 2020 年 4 月 20 日
Hello, can anyone help me with this one? I have this array called 'd'. I want to generate a new array called ratio. Answers for array ratio should be calculated as the given example. d1,d2,... are numbers in descending order. I have around 100 numbers in array d. So I am trying to run a code to do the calculations automatically. Thank you.
d=[d1;d2;d3;d4] % example d=[4;3;2;1]
size=length(d)
ratio=zeros(size,size-1)
%calculations
ratio=[0 0 0 ;
d1/d2 0 0 ;
d1/d3 d2/d3 0 ;
d1/d4 d2/d4 d3/d4 ]

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 20 日
編集済み: Ameer Hamza 2020 年 4 月 20 日
try this
d = [4 3 2 1];
ratio = tril(d./d.', -1);
ratio(:,end) = [];
Result:
ratio =
0 0 0
1.3333 0 0
2.0000 1.5000 0
4.0000 3.0000 2.0000
  2 件のコメント
Dinu Th.
Dinu Th. 2020 年 4 月 20 日
Thank you for the quick response. It works.
Ameer Hamza
Ameer Hamza 2020 年 4 月 20 日
I am glad to be of help.

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

その他の回答 (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