필터 지우기
필터 지우기

function rand with variables

조회 수: 1 (최근 30일)
Talmor Shlomovich
Talmor Shlomovich 2019년 11월 13일
답변: Fangjun Jiang 2019년 11월 13일
hi,
i have 3 variables. for example:
a = 1
b = 2
c = 3
and i want to make a vector with 10 numbers only from the variables (a,b,c)
like "rand" but instead of random numbers - from the variable

답변 (2개)

M
M 2019년 11월 13일
You can use something like this, adapt it to your case:
a = 1;
b = 2;
c = 3;
A = [a b c];
nb = 10;
vec = zeros(1,nb);
for i = 1 : nb
idx = randi([1 numel(A)]);
vec(i) = A(idx);
end

Fangjun Jiang
Fangjun Jiang 2019년 11월 13일
a=10;b=20;c=30;
mat=[a,b,c];
index=randi([1 3],1,10);
out=mat(index)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by