hi, i use the following code . the output is 15 values , i want stored this values automatically in array in order to Call these values again
3 次查看(过去 30 天)
显示 更早的评论
for sw=1:15
n=[10;20;30;40;50;60;70;80;90;100];phi=0.5;
s=2;
z0=0.4;
index=0;
o=10;
for nn=1:o
a=normrnd(0,s^2,n(nn),1);
z=zeros(n(nn),1);
z(1)=phi*z0+a(1);
for i=2:n(nn)
z(i)=phi*z(i-1)+a(i);
end
for i=2:n(nn)
g(i)=z(i)*z(i-1);
end
k=sum(g,2);
num= (n(nn)-2)*k;
for i=3:n(nn)
f(i)=z(i-1)*z(i-1);
end
p=sum(f,2);
den=(n(nn)-1)*p;
index=index+1;
ma(index)=n(nn);
phihat(index)=num/den;
end
for i=1:o
da(i)=(phihat(i)-phi)^2;
end
MSEreal=num2str((sum (da)/(o)),'% .10f')
end
0 个评论
采纳的回答
Star Strider
2016-8-24
I would just do:
MSEreal(sw) =sum((da)/(o));
There’s absolutely no need to convert them to a string array, since you have to convert them back to numeric to use them later. If you want to round them to 10 digits to the right of the decimal, use the latest version of the round function, or this anonymous funciton to do the same thing:
roundn = @(x,n) round(x .* 10.^n)./10.^n; % Round ‘x’ To ‘n’ Digits, Emulates Latest ‘round’ Function
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!