필터 지우기
필터 지우기

How make Random sampling set multiple times

조회 수: 5 (최근 30일)
HAN TAEHEE
HAN TAEHEE 2020년 12월 3일
답변: Deepak 2024년 10월 8일 13:49
Hi im beginer of matlab and now im try to make randomsapling
mulitple times.
so i want to make random samping from same data set multiple times
my code this x = datasample(data,k)
so i want to make
x = datasample(data,k)
x1 = datasample(data,k)
x2 = datasample(data,k)
....
xn = datasample(data,k)
so i want to make above code just one code and make one data set.
thank you!

답변 (1개)

Deepak
Deepak 2024년 10월 8일 13:49
To my understanding, you have written MATLAB code to generate “n” random samples from the given input data. Now, you want to automate this process and generate only one output dataset from all the generated samples.
To accomplish this task, we can pre-allocate a matrix to store the output sample data. Next, we can iterate “n” times using for loop to generate the samples and store them in the output matrix using array indexing in MATLAB.
Here is the MATLAB code that addresses this task:
data = 1:100;
k = 10;
n = 5;
% Preallocate a matrix to store the samples
samples = zeros(n, k);
% Perform random sampling multiple times
for i = 1:n
samples(i, :) = datasample(data, k);
end
disp('All samples in a single dataset:');
disp(samples);
Please find attached the documentations of “loops, “zeros” and “array indexing” in MATLAB for reference:
I anticipate this will address the issue.

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by