display 4 consecutive numbers in array
Mostra commenti meno recenti
I have the Array a= 9 10 11 12 17 18 19 20 23 24 How can i get the code to display when the 4 indices are consecutive and when they appear. example: 9 10 11 12 and 17 18 19 20
Risposta accettata
Più risposte (1)
David Sanchez
il 8 Ott 2014
a= [9 10 11 12 17 18 19 20 23 24];
for k=1:(length(a)-3) % k=2
if a(k:k+3)==(a(k):a(k)+3)
fprintf('repeition in position %g: \n',k);
disp(a(k:k+3));
end
end
2 Commenti
Kole
il 8 Ott 2014
Categorie
Scopri di più su Data Types in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!