How can I select random number from a range that involves my previous size of data?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, in the piece of code below (esp: the bold) i want to random select numbers from location(i,col1)+21 to the end of the element as the same size as my Seg_A{i,1}, I wrote the one below but give nothing.
elseif location(i,col2)>location(i,col3) - flanks; %end
Seg_A{i,1} = seq_f{i,:}(location(i,col1):location(i,col2)+20);
N_seg{i,1} = seq_f{i,:}(location(i,col1)+21: size(Seg_A{i,1}))
Thanks in Advance
0 Commenti
Risposte (1)
BhaTTa
il 18 Ago 2025
Modificato: BhaTTa
il 18 Ago 2025
Hey @Koko08, below i have attached MATLAB snippet that: picks a contiguous random segment starting at location(i,col1)+21 with the same length as Seg_A{i,1}, if it fits. Please take it as reference and modify it accordingly
% Build Seg_A
Seg_A{i,1} = seq_f{i,:}(location(i,col1) : location(i,col2)+20);
% Random segment of same length
L = numel(Seg_A{i,1});
earliestStart = location(i,col1) + 21;
latestStart = numel(seq_f{i,:}) - L + 1;
if earliestStart <= latestStart
rStart = randi([earliestStart, latestStart]);
N_seg{i,1} = seq_f{i,:}(rStart : rStart + L - 1);
else
N_seg{i,1} = [];
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Random Number Generation 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!