sum up each column of my loop matlab

2 ビュー (過去 30 日間)
mabdorab
mabdorab 2016 年 12 月 7 日
コメント済み: Geoff Hayes 2016 年 12 月 7 日
for i=[0:1:30000];
R=[poissrnd(0.0000407430680),poissrnd(0.000472626),poissrnd(0.002497495),poissrnd(0.996989136)];
end
How can I get matlab to sum up each value of the R vector for all 30,000 simulations.
once its found the values from 1:i:30,000 I want it to add all the values in the first column, then all values in the second column, etc and have the result in one vector
  2 件のコメント
mabdorab
mabdorab 2016 年 12 月 7 日
sorry and just to add, if I wanted to find out where the values in columnSums came from how would I do this, so I know which iteration it came from. I am doing a forecast for nuber of claims and knowing where the counts came from may be required in my analysis.
Thanks in advance
Geoff Hayes
Geoff Hayes 2016 年 12 月 7 日
columnSums is an array of the sums of each column of R....where R is an array of Poisson random numbers for 30000 iteration. Please clarify your question because it isn't clear what you are asking.

サインインしてコメントする。

回答 (1 件)

Geoff Hayes
Geoff Hayes 2016 年 12 月 7 日
mabdorab - it sounds like you want to create a 30000x4 array of Poisson random numbers. Try presizing your R and then update each row as you iterate over k. For example,
n = 30000;
R = zeros(n,4);
for k=1:n
R(k,:) = [poissrnd(0.0000407430680),poissrnd(0.000472626),poissrnd(0.002497495),poissrnd(0.996989136)];
end
Then you can use sum to sum your columns as
columnSums = sum(R);
  2 件のコメント
mabdorab
mabdorab 2016 年 12 月 7 日
perfect thank you so much.
What would I do if I wanted the columnSums first value to be called A, second value B, third value C, fourth value D, and had them result seperatley?
really appreciate the fast response, my project is due in 2 days.
Geoff Hayes
Geoff Hayes 2016 年 12 月 7 日
Do you mean that you want to create a table? For example,
array2table(columnSums, 'VariableNames',{'A','B','C','D'});

サインインしてコメントする。

カテゴリ

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