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

采纳的回答

Star Strider
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 CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by