首页 > 解决方案 > 生成更大的随机整数 - MATLAB

问题描述

尝试为其分配适当的值x会导致 1 到 60 之间的随机整数。有什么建议吗?我做到了randn,但一次又一次地得到少量的数字。这是到目前为止的代码:

function s = Q11sub1(x)
    x =                 % <------ Question is what goes here
    if x <= 30      
        s = "small";       
    elseif x > 30 & x <= 50       
        s = "medium";  
    else    
        s = "high";  
    end
end

标签: matlabrandominteger

解决方案


使用randi

randi(60)

这将为您提供 1 到 60 之间的伪随机整数。

参考:https ://www.mathworks.com/help/matlab/ref/randi.html


推荐阅读