Take values from array within nested loop

Want to implement
RMSE= sqrt{1/K* summation k=1:K [(theta_est-theta_true)]^2}
theta_est and theta_true may be of different length
error=0;
for k=1:K
for m=1:length(theta_est)
for t=1:length(theta_true)
error=error+(theta_est(m,k)-theta_true(t,k)).^2
RMSE=sqrt(1/K*error)
end
end
end

1 件のコメント

David Sanchez
David Sanchez 2016 年 6 月 30 日
And what is your problem?

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

回答 (1 件)

dpb
dpb 2016 年 6 月 30 日

0 投票

"Implement RMSE= sqrt{1/K* summation k=1:K [(theta_est-theta_true)]^2} [where] theta_est and theta_true may be of different length"
Well, there's no definition of a difference where there aren't comparable entities so your choice is either compute over the min(length(theta_est),length(theta_true)) or, if the two vectors represent a given time of commensurate duration, interpolate the shorter or decimate the longer to match. The first option is simply
K=min(length(theta_est),length(theta_true));
RMSE=rms(theta_est(1:K)-theta_true(1:K)); % rms from Signal Processing Toolbox

カテゴリ

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

タグ

質問済み:

2016 年 6 月 30 日

回答済み:

dpb
2016 年 6 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by