How can I select random number from a range that involves my previous size of data?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
BhaTTa
am 18 Aug. 2025
Bearbeitet: BhaTTa
am 18 Aug. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!