Short way to write this function?

2 ビュー (過去 30 日間)
José Antonio Torres
José Antonio Torres 2019 年 3 月 19 日
Hello,
Does anyone know of a solution to this problem?
function[y]=rayleigh_product(x,x2,x3,x4) % For up to 55 storm steps (threshold = 4 in the original case)
global SDSRp_ Tz_Tz_
y=(1-exp(-0.5*(x/SDSRp_(x2,x3,x4,1))^2))^(10800/Tz_Tz_(x4,2))...
*(1-exp(-0.5*(x/SDSRp_(x2,x3,x4,2))^2))^(10800/Tz_Tz_(x4,3))...
*(1-exp(-0.5*(x/SDSRp_(x2,x3,x4,3))^2))^(10800/Tz_Tz_(x4,4))...
*(1-exp(-0.5*(x/SDSRp_(x2,x3,x4,4))^2))^(10800/Tz_Tz_(x4,5))...
*(1-exp(-0.5*(x/SDSRp_(x2,x3,x4,5))^2))^(10800/Tz_Tz_(x4,6))...
*(1-exp(-0.5*(x/SDSRp_(x2,x3,x4,6))^2))^(10800/Tz_Tz_(x4,7))...
And it goes on till 55 parts. The code works now, but it would be useful to have the option of just doing the product of any number of functions. I.e, if I want to do the same analysys with a different data set.

採用された回答

Walter Roberson
Walter Roberson 2019 年 3 月 19 日
編集済み: Walter Roberson 2019 年 3 月 19 日
y = prod(arrayfun(@(IDX) 1-exp(-0.5*(x./SDSRp_(x2,x3,x4,IDX).^(10800./Tz_Tz_(x4,IDX+1)))), 1:55));
This assumes that SDSRp_ and Tz_Tz_ are functions. If they were arrays then there is more potential for vectorization.
Is it practical to rewrite the two functions to accept a vector for the last parameter?
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 3 月 19 日
prod((1-exp(-0.5 *(x./SDSRp_(x2, x3, x4, 1:55)))).^(10800./Tz_Tz_(x4,1+(1:55))))
I think I had some brackets in the wrong place before.
José Antonio Torres
José Antonio Torres 2019 年 3 月 19 日
Thank you so much Walter! This is just what I needed

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by