Uninterrupted segment length?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Gavin Rumbaugh
am 28 Nov. 2016
Kommentiert: Qisq
am 27 Apr. 2018
Let's say I have an array indexes:
Indexes = [1122221122111211112222222]
How do I get the length of uninterrupted 2s? I want to output to be
output=[ 4 2 1 7]
0 Kommentare
Akzeptierte Antwort
bio lim
am 28 Nov. 2016
For a number that has longer digits, I am not sure. However, if it is within acceptable number of digits
format long
Indexes = [112222112211121];
newIndexes=str2double(regexp(num2str(Indexes),'\d','match'))
coffee = find(diff([-1 newIndexes -1]) ~= 0);
length = diff(coffee);
output = length(1+(newIndexes(1)==1):2:end);
The output is:
output =
4 2 1
0 Kommentare
Weitere Antworten (1)
Roger Stafford
am 28 Nov. 2016
Bearbeitet: Roger Stafford
am 28 Nov. 2016
f = find(diff([false,Indexes==2,false])~=0);
output = f(2:2:length(f))-f(1:2:length(f));
1 Kommentar
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices 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!