Need help to vectorize a for loop

Pls help... how to vectorise this for loop
unimodal=[28 42 46 49 52 55 58 61 64 68 82]
for n=1:11
ru(n)=(unimodal(n)-min(unimodal))/(max(unimodal)-min(unimodal));
end
for n=1:11
fu(n)=(n-1)/(length(unimodal)-1)
end
for n=1:11
ju(n)=0.5*ru(n)+0.5*fu(n);
end

 採用された回答

David Hill
David Hill 2019 年 12 月 8 日

0 投票

unimodal=[28 42 46 49 52 55 58 61 64 68 82];
ru=(unimodal-min(unimodal))/(max(unimodal)-min(unimodal));
fu=(0:length(unimodal)-1)/(length(unimodal)-1);
ju=0.5*ru + 0.5*fu;

1 件のコメント

Johnny
Johnny 2019 年 12 月 8 日
Thanks a lot!is this the most efficient way to get the result?

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeParallel Computing Toolbox についてさらに検索

質問済み:

2019 年 12 月 8 日

コメント済み:

2019 年 12 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by