필터 지우기
필터 지우기

problem in matlab programs

조회 수: 3 (최근 30일)
dab483
dab483 2012년 7월 6일
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)

채택된 답변

Jan
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
  댓글 수: 1
dab483
dab483 2012년 7월 6일
thank you so much.. now i can plot when no_of_runs more than 1. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by