problem in matlab programs
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I'm having problem to plot my figure when i try to run the program several times to get an average value of rmse. I know there is something wrong the way i save the data for plotting, but i dont know how to solve it.
if i set the no_of_runs more than 1,let say 2 the previous data will still be there and making the data save in the xArray much bigger (1x201), hence the vector of t (1x101 double) and xArray and others will not be the same any more and fail to plot.
how do i make the array will still be (1x101 double) everytime when no_of_runs more than 1? thank you.
tf = 100; % simulation length
no_of_runs=2
x=1; %%initialize
xhatukf1Array = 1;
Pukf1= ..
Pukf1array = diag(Pukf1);
%%start program
for k=1: no_of_runs
for t=1:tf
.....equations...+++
x= ...
z=....
Kukf1 = Pxy1 /(Py1);
xhatukf1 = xhatukf1 + Kukf1 * (z - zhat1);
Pukf1 = Pukf1 - Kukf1 * Py1 * Kukf1';
% Save data for plotting.
xArray = [xArray x];
xhatukf1Array = [xhatukf1Array xhatukf1];
Pukf1array = [Pukf1array diag(Pukf1)];
end %%(end t loop)
t = 0 : tf;
figure;
plot(t, xArray(1,:),'k-',t,xhatukf1Array(1,:),'m');
xlabel('Seconds');
legend('True Position','ukf2n+1');
rmsError_ukf2N(k) = sqrt(inv(tf)*sum((xArray-xhatukf1Array).^(2)));
end %%(end k loop)
0 件のコメント
採用された回答
Jan
2012 年 7 月 6 日
for k=1: no_of_runs
xArray = [];
...
end
A pre-allocation would be more efficient:
for k=1: no_of_runs
xArray = zeros(<LENGTH_OF_x>, tf); % I do not know "size(x)"
for t=1:tf
xArray(:, t) = x;
end
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Graphics Object Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!