Some basic MATLAB questions
조회 수: 3(최근 30일)
Given a vector u of dimension 20x1 consisting of random variables from a uniform-
distribution (distributed on [0,1]).
- Create a code in MATLAB,
- that creates the vector u,
- which contains both 'for loops' and 'if loops',
- and specifies for all values in the vector u in which quarter the number lies.
I managed to create the vector and split it into the quarters. I dont get how to implant the for and if loops.
Can someone help me out ? :((
Torsten 2022년 6월 14일
n = 20;
r = zeros(n,1)
r(i) = rand;
if r(i) < 0.25
quarter(i) = ...
elseif r(i) >=0.25 && r(i) < 0.5
Can you take it from here ?
Walter Roberson 2022년 6월 14일
But be careful with the exact boundaries that are multiples of 1/4. For each of those exact values you should write down which bin you want to result, and test your code to make sure it gives those results.
0, ¼, ½, ¾, 1 is five boundaries not 4, and you need to design with that in mind.