create one to one function between a rows of 2 vectors
2 views (last 30 days)
Show older comments
Alden Robertson
on 24 Nov 2017
Commented: Alden Robertson
on 26 Nov 2017
I'm fairly new to Matlab and I'm looking to create a function that assigns the first n numbers in their binary form to a random number between 0 and 1. This is what I've got so far but it isnt really working.
n=3
d2b = de2bi(0:2^n-1)
randnos = rand(2^n,1)
f=@(x) randnos(find(d2b(x,:)==x));
f(d2b(1,:))
Any help would be greatly appreciated!
0 Comments
Accepted Answer
Walter Roberson
on 24 Nov 2017
Take the input binary number and convert it to decimal, add 1, and use that to index the table of random numbers.
More Answers (0)
See Also
Categories
Find more on Whos 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!