필터 지우기
필터 지우기

I have a program like this (MATLAB function on Simulink): And I want it to stop when I get 256 values. Does the randi function work almost continuously?

조회 수: 2 (최근 30일)
function [ key ] = keyGen()
key = zeros(1,256);
for i = 1:256
if(rem(i,9)==0)
key(i) = i;
else
x = 261;
while rem(x,9) == 0 || ~isempty(find(key == x, 1)) || i == x
x = randi([1,256]);
end
key(i) = x;
end
end
end

답변 (1개)

Benjamin Thompson
Benjamin Thompson 2022년 3월 7일
You can call randi once to get a set of integer random numbers as a vector or matrix. Call randi(N, X, Y), where N is the max integer value that you want randi to return, X is the number of rows in the output, Y is the number of columns in the output.

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by