sum up each column of my loop matlab
Show older comments
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 Comments
mabdorab
on 7 Dec 2016
Geoff Hayes
on 7 Dec 2016
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.
Answers (1)
Geoff Hayes
on 7 Dec 2016
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 Comments
mabdorab
on 7 Dec 2016
Geoff Hayes
on 7 Dec 2016
Do you mean that you want to create a table? For example,
array2table(columnSums, 'VariableNames',{'A','B','C','D'});
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!