How to generate sample Randomly in Matlab
古いコメントを表示
Hello everyone i hope you are doing well.
I have the following code which generate 4000 sample for a value of 200. and output is the if 1x4000
I want the value to be random from 1 to 1000. and save the result of each value in seperate row
for example value=1 it has 4000 samples in first row, after value=100 it has 4000 samples in second row
value= [200];
Numberofsample = [4000];
output = repmat(value,1,(ceil(sum(Numberofsample)/length(Numberofsample))));
回答 (1 件)
Benjamin Thompson
2022 年 3 月 3 日
0 投票
>> output = randn(1,4000);
>> size(output)
ans =
1 4000
12 件のコメント
Med Future
2022 年 3 月 3 日
Benjamin Thompson
2022 年 3 月 3 日
Are you creating a plot where some data is the x axis values (not random, if so what is it) and the random values are on the y axis?
Or if you are just asking for the result to be a column vector instead of a row vector, swap the order of arguments to randn.
Med Future
2022 年 3 月 3 日
Benjamin Thompson
2022 年 3 月 3 日
You use randi for a uniform distribution over a specific range, and then plot to plot the results:
>> output = randi(1000,1,4000);
>> figure, plot(1:4000,output);
Med Future
2022 年 3 月 3 日
Med Future
2022 年 3 月 3 日
Benjamin Thompson
2022 年 3 月 3 日
If you are looking for a row vector containing the same random number repeated 1000 times, that would be:
output = randi(100, 1,1) * ones(1,1000);
If this is not what you want please try some of these examples and see if you can make it look the way you want. If you have more problems please ask a question with more information, perhaps a small example of the larger data set you want to create.
Walter Roberson
2022 年 3 月 3 日
編集済み: Walter Roberson
2022 年 3 月 3 日
value = [1, 100, 200];
output = repmat(randi(1000, 1, 4000), length(value), 1);
Med Future
2022 年 3 月 3 日
Walter Roberson
2022 年 3 月 3 日
value = [1, 100, 200];
output = repmat(randi(1000, length(value), 1), 1, 4000);
Med Future
2022 年 3 月 3 日
Walter Roberson
2022 年 3 月 3 日
The method remains the same. Take one random quantity for each "value" and repeat it out to the 4000 or whatever you need.
If the class data is quantized, then you can use a random integer in the range of 1 to the number of quantized values, and use that to index the original data, like
output = repmat( MyCategories(randi(length(MyCategories), length(value), 1), 1, NumberOfCopies);
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
