Create a vector with specific intervals

13 visualizzazioni (ultimi 30 giorni)
Tanvir Hossain
Tanvir Hossain il 5 Mag 2020
Risposto: Mohammad Sami il 5 Mag 2020
I want to create two vectors. vectors are like following
limit = 100; % limit can be any number
a = [1,4,5,8,9,12,13 ..... limit]
b = [2,3,6,7,10,11,.........limit]

Risposte (1)

Mohammad Sami
Mohammad Sami il 5 Mag 2020
You can split it into 4 sequences. then merge it back together to create your desired vector.
limit = 100;
a1 = 4:4:limit;
a2 = 5:4:limit;
b1 = 2:4:limit;
b2 = 3:4:limit;
a = sort([1 a1 a2]);
b = sort([b1 b2]);

Categorie

Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by