我必须在随机矩阵中选择一个随机列,但有时程序会选择一个比矩阵大小更大的随机数。
n = 3 + (10-3)*rand(1,1); 
t = round(n); 
x = randi(t,t); 
u = 3 + (10-3)*rand(1,1);
f = round(u);
if f < n & f ~= 0
for k = 1:t
e(k,1) = x(k,f);
end
end所以我用if来解决这个问题,但是当命题f < n & f ~= 0为假时,我不知道如何重新计算随机数。请帮帮忙
发布于 2021-06-10 20:11:17
不是100%这是你想要做的,但是:
t = randi( [3,10], 1 );   % select a random number 't' in the range 3:10
x = randi( t, t );        % create a t-by-t matrix of random values in the range 1:t
r = randi( t );           % select a random number in the range 1:t
c = x(:,r)                % select the rth column from 'x'https://stackoverflow.com/questions/67912363
复制相似问题