Choosing a random number from a linearly spaced vector

5 views (last 30 days)
I get the error as size inputs must be scalar. I want to choose one random value from the linearly spaced set of values for every trial. So, everytime I run yy, I should get a random value from the xx vector. Please help on how I go about it.
xx= linspace(1,2,9) %a vector of linearly spaced values
yy= randperm(xx) %pick a random value from xx

Accepted Answer

KSSV
KSSV on 17 Jan 2022
xx= linspace(1,2,9) %a vector of linearly spaced values
xx = 1×9
1.0000 1.1250 1.2500 1.3750 1.5000 1.6250 1.7500 1.8750 2.0000
yy = xx(randi(9,1))
yy = 1.2500

More Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox 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!