So i want to calculate an r value 5 different times then find the mean of the 5 calculated values.(adsbygoogle = window.adsbygoogle || []).push({});

I have 2,187 data points. the first line of code generates 100 random points 1-2187.

The code has a bug but my major issue is it calculates r then loops again calculates r, loops again calculates r and there is no way to sum this. How can I edit my code.

for i = 1:5

randomdata = round(rand(100,1).*2187);

xval = x(randomdata);

yval = y(randomdata);

numerator = length(xval)*nansum(xval.*yval) - (nansum(xval)*nansum(yval));

xsumsquared = nansum(xval)^2;

ysumsquared = nansum(yval)^2;

dddx = sqrt(length(xval)*nansum(xval.^2) - xsumsquared);

ddy = sqrt(length(xval)*nansum(yval.^2) - ysumsquared);

demonator = dddx * ddy;

r = numerator/demonator;

end

thanks

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# MATLAB sum loop issue

Tags:

Loading...

Similar Threads - MATLAB loop issue | Date |
---|---|

Matlab Arduino-MATLAB communication using SerialEvent() for PID Loop | Oct 28, 2016 |

Matlab -- how can i use a FOR loop if I have 2 variables changing | Oct 12, 2016 |

Matlab What is wrong with this WHILE loop? | Aug 26, 2016 |

Simple MATLAB loop | Oct 30, 2015 |

Roots of Polynomials by loop in matlab | May 6, 2015 |

**Physics Forums - The Fusion of Science and Community**