How to generate random number within specific values
5 ビュー (過去 30 日間)
古いコメントを表示
Hi all, i hope you are doing well.
i want to generate random number of specific range using for loop and saved the array in mat file
how can i do that
i have the following code which pick value manually
like prfSTG value between 200 to 1200
and n_pulsesSTG value between 200 to 1000
prfSTG = [200 400 800 1000 1200 ];
n_pulsesSTG = [800 800 800 800 800 800 ];
prfSTG = repmat(prfSTG,1,(ceil(sum(n_pulsesSTG)/length(n_pulsesSTG))));
2 件のコメント
Jan
2022 年 2 月 21 日
The question is not clear. Which are the specifications for the random matrix? The saving works by the save command.
採用された回答
Jan
2022 年 2 月 21 日
Sorry, your information are still not clear. I try it with a most likely not satisfying solution to demonstrate the problem:
% prfSTG value between 200 to 1200
prfSTG = rand * 1000 + 200;
% n_pulsesSTG value between 200 to 1000
n_pulsesSTG = rand * 800 + 200;
% apply for loop in that so the values store in
for k = 1:1 % completely useless loop
rfSTG = repmat(prfSTG,1,(ceil(sum(n_pulsesSTG)/length(n_pulsesSTG))));
end
What is missing to solve your needs?
2 件のコメント
その他の回答 (1 件)
Arif Hoq
2022 年 2 月 21 日
Try this:
prfSTG=randi([200 1200], 1,5); % generating random number between 200 and 1200
n_pulsesSTG = randi([200 1000], 1,5); % generating random number between 200 and 1000
C=cell(1,5)
for i=1:length(prfSTG)
C{i} = repmat(prfSTG(i),1,(ceil(sum(n_pulsesSTG)/length(n_pulsesSTG(i)))));
end
Matrix=[C{:}];
output=reshape(Matrix,length(C{1, 1}),[]);
plot(output, 'LineWidth', 3)
0 件のコメント
参考
カテゴリ
Help Center および 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!