Assigning random numbers to multiple vectors
Show older comments
Hello,
Please allow me to preface this question with an apology as I am a novice programmer and novice MATLAB user. I am trying to assign the uniformly distributed random numbers of weightEggs to the four vectors listed (sEggs, mEggs, lEggs, and xlEggs) to no avail. Can someone please tell me what I am doing incorrectly? My code is below. Thank you!
%Create a vector called weightEggs of size 1x100 containing random numbers
%(taken from the uniform distribution) between 45 and 85.
weightEggs = randi([45 85],1,100);
sEggs = weightEggs <= 53
mEggs = (weightEggs > 53) | (weightEggs <= 63)
lEggs = (weightEggs > 63) | (weightEggs <= 73)
xlEggs = weightEggs > 73
if weightEggs <= 53
disp([ num2str(weightEggs) ' are small eggs.' ])
weightEggs = sEggs;
elseif weightEggs > 53 | weightEggs <= 63
disp([ num2str(weightEggs) ' are medium eggs.' ])
weightEggs = mEggs;
elseif weightEggs > 63 | weightEggs <= 73
disp([ num2str(weightEggs) ' are large eggs.' ])
weightEggs = lEggs;
elseif weightEggs > 73
disp([ num2str(xlEggs) ' are extra-large eggs.' ])
weightEggs = xlEggs;
end
Accepted Answer
More Answers (0)
Categories
Find more on Uniform Distribution (Continuous) 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!