i am trying to add the value of a certain function to an array, but there seems to be some error. the code is as follows. could you please help? trying to store the value of Thetahat into A for every x.
1 回表示 (過去 30 日間)
古いコメントを表示
function [inseed] = optsim (inseed, nreps)
sum = 0;
sum2 = 0;
for x = 0:5:60
for j= 1:nreps
[inseed, profit] = poisprofit(inseed, x);
sum = sum+profit;
sum2 =sum2 + profit^2;
end
Thetahat = sum/nreps;
sigmahat = sqrt(sum2/nreps-Thetahat^2);
sehatThetahat = sigmahat/sqrt(nreps);
A(x)= profit;
D(x) = x;
end
end
0 件のコメント
回答 (1 件)
Walter Roberson
2017 年 2 月 14 日
編集済み: Walter Roberson
2017 年 2 月 14 日
Only positive integers can be used as indices.
You should use a pattern more like
sum1 = 0;
sum2 = 0;
xvals = 0:5:60;
for xidx = 1 : length(xvals)
x = xvals(xidx);
for j= 1:nreps
[inseed, profit] = poisprofit(inseed, x);
sum1 = sum1+profit;
sum2 =sum2 + profit^2;
end
Thetahat = sum1/nreps;
sigmahat = sqrt(sum2/nreps-Thetahat^2);
sehatThetahat = sigmahat/sqrt(nreps);
A(xidx)= profit;
D(xidx) = x;
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!