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

4 次查看(过去 30 天)
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