How to generate random number within specific values
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Jan
il 21 Feb 2022
The question is not clear. Which are the specifications for the random matrix? The saving works by the save command.
Risposta accettata
Jan
il 21 Feb 2022
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 Commenti
Più risposte (1)
Arif Hoq
il 21 Feb 2022
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 Commenti
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!