Setting element of a variable X to zero with conditional statement, and putting it into new variable Y?
Show older comments
After generating random numbers and putting them in a variable X, how can I give a statement that if element of X is more than 0.3 and less than 0.6, turn it into 0 and put it in a new variable which I will call Y?
Answers (2)
madhan ravi
on 16 Mar 2019
Edited: madhan ravi
on 16 Mar 2019
idx = ( x > 0.3 ) & ( x < 0.6 ) ; % index into whichever variables you like and assign the value/values
x(idx) % grabs values of x within the range
2 Comments
AKROMJON AKHMADJONOV
on 16 Mar 2019
Edited: AKROMJON AKHMADJONOV
on 16 Mar 2019
madhan ravi
on 16 Mar 2019
What I have shown should get you started , I am not going to finish your homework sorry.
AKROMJON AKHMADJONOV
on 16 Mar 2019
0 votes
Categories
Find more on Logical 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!