Assigning random numbers to multiple vectors
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Uniform Distribution (Continuous)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!