correct use of randsrc function
14 次查看(过去 30 天)
显示 更早的评论
out = randsrc(1,1,[-3 -1 1 3; 0.1 0.4 0.4 0.1])
Error: Undefined function 'randsrc' for input arguments of type 'double'.
Aim: I want to display a random number from the set -3, -1, 1, 3 each with respective probabilities 0.1, 0.4, 0.4, 0.1
0 个评论
回答(2 个)
Scott MacKenzie
2021-6-9
编辑:Scott MacKenzie
2021-6-9
There are lots of ways to do this, I suppose. Here's what I put together -- with a pesky twist. The weighting is built-in to the set. Just pull a value from set at random and the weighting is a natural outcome.
% define set
set = [-3 -1 -1 -1 -1 1 1 1 1 3];
% get random value from set (with built-in weighting)
set(randi([1 length(set)],1))
Walter Roberson
2021-6-10
randsrc() is from the Communications System Toolbox https://www.mathworks.com/help/comm/ref/randsrc.html
See https://www.mathworks.com/matlabcentral/answers/415418-how-to-correct-randsrc-in-matlab for some replacements.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dynamic System Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!