Which is the simplest way to create neighbourhood pairs?

4 vues (au cours des 30 derniers jours)
Mr M.
Mr M. le 21 Avr 2015
Modifié(e) : Andrei Bobrov le 24 Avr 2015
from [1,2,3,7,8,9] to [1 2; 2 3; 3 7; 7 8; 8 9]

Réponses (2)

Radha Krishna Maddukuri
Radha Krishna Maddukuri le 24 Avr 2015
Modifié(e) : Radha Krishna Maddukuri le 24 Avr 2015
I hope this helps.
B = zeros(numel(A)-1,2);
for i =1:1:(numel(A)-1)
B(i,:) = [A(i) A(i+1)];
end

Andrei Bobrov
Andrei Bobrov le 24 Avr 2015
Modifié(e) : Andrei Bobrov le 24 Avr 2015
hankel(a(1:end-1),a(end-1:end))
or
[a(1:end-1)', a(1:end-1)'+1]
or
a1 = a(1:end-1)
bsxfun(@plus,a1(:),[0 1])

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by