Loop over randn of vectors
Show older comments
I have one vector of twenty "ideal" values, and I'm able to add normally distributed error to those values by
error = good+1*randn(size(good));
but what I want to do is generate a 20x100 matrix of these values. Specifically what I want to do is calculate a vector of another variable that depends on the value of this one, so that I get an output of 20x100 of each.
I'm trying to use a for loop to accomplish this but I'm clearly doing it wrong:
for i = 1:100;
bad(i) = good+1*randn(size(good));
newVar(i) = stuff/bad(i)
end
I'm getting the age-old 'elements of A and B must be the same'. I've tried preallocating the size of "bad", subscripting good (i.e. good(i)) in one and both places and I don't know what else to try. Why will this work for one iteration but not 100?
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!