Hello, I have an array of values in "In", I would like to extract the samples in "In" between the indices specified in "SIdx" and "EIdx". SIdx and EIdx are also arrays.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Krishna Ghanakota
am 9 Mär. 2024
Kommentiert: Voss
am 9 Mär. 2024
I would like to acheive the functionality without using a for loop. Currently the code is written as
Working Code :
In = 1:100;
SIdx = [1 9 33 76];
EIdx = [5 13 42 83];
Out = {};
for i = 1:length(SIdx)
Out = [Out; {In(SIdx(i):EIdx(i))}];
end
Out =
4×1 cell array
{[ 1 2 3 4 5]}
{[ 9 10 11 12 13]}
{[33 34 35 36 37 38 39 40 41 42]}
{[ 76 77 78 79 80 81 82 83]}
Is there a way to acheive the same functionality without using a for loop.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 9 Mär. 2024
In = 1:100;
SIdx = [1 9 33 76];
EIdx = [5 13 42 83];
Out = arrayfun(@(S,E) In(S:E), SIdx, EIdx, 'uniform', 0).'
2 Kommentare
Siehe auch
Kategorien
Mehr zu Array Geometries and Analysis 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!