フィルターのクリア

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

回答 (1 件)

Walter Roberson
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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by