decreasing the number of for-loops

2 ビュー (過去 30 日間)
som
som 2012 年 1 月 25 日
I've written a program having some loops. I aim to decrease the number of loops as well as the run-time of program. How can I do this?? a part of this mentioend program is as below:
for t = 1:T
for i = 1:M
for j = 1:M
Pr{t}(i,j) = 1 / sqrt(2*pi*S(1,t)) * exp(-1/(q(i,t)-f(j,t))^2);
end
end
end
Thanks,
  1 件のコメント
Jan
Jan 2012 年 1 月 25 日
I've formatted the code. Please use the "{} Code" button to apply the correct formatting. Thanks.

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

回答 (1 件)

Jan
Jan 2012 年 1 月 25 日
for t = 1:T
Pr{t} = 1 / sqrt(2*pi*S(1,t)) * exp(-1 ./ (bsxfun(@minus, q(:,t), f(:,t).').^2);
end
Please test this. I cannot run Matlab currently.
[EDITED] Small typo in the BSXFUN arguments.
  2 件のコメント
som
som 2012 年 1 月 25 日
Dear Jan, it doesn't work appropriately.
Jan
Jan 2012 年 1 月 26 日
Posting the error message would be fine. Be aware, that I cannot run the code, because you did not provide any values for the variables. But when I cannot run the code, I cannot see the error message, which contains useful imformation to locate and fix the problem.
Anyhow, I've found one typo in the code and fixed it.

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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by