How can I select random number from a range that involves my previous size of data?

조회 수: 1 (최근 30일)
Koko08
Koko08 2019년 9월 14일
편집: BhaTTa 2025년 8월 18일
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

답변 (1개)

BhaTTa
BhaTTa 2025년 8월 18일
편집: BhaTTa 2025년 8월 18일
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

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by