How can I select random number from a range that involves my previous size of data?
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
BhaTTa
on 18 Aug 2025
Edited: BhaTTa
on 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 Comments
See Also
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!