How to duplicate some values in vector , while each value is duplicate in different number of times?

3 visualizzazioni (ultimi 30 giorni)
I have a 1*48 row vector: [1 0 2 0 3 0 2 0 3 0 3.....] i want to get a 1*168 vec in a way that duplicate (1,2,3 ) four times each number and 0 is duplicate three times, and keep the order like this without changing,
Trialsorder =[1,3,1,2,3,2,1,1,1,3,2,1,3,3,1,2,1,2,3,2,2,3,3,2];
Trialsorder_temp=upsample(Trialsorder,2);
thanks you
  2 Commenti
Jan
Jan il 14 Giu 2022
I do not understand the procedure. What does "duplicate (1,2,3 ) four times each number and 0 is duplicate three times" mean?
Please post a short input and output example.
Kesem Ester Ozen
Kesem Ester Ozen il 14 Giu 2022
if the vector is a=[1 0 2 0 3 0 3 0];
then i will like to get a vector like this:
>> [ 1 1 1 1 0 0 0 2 2 2 2 0 0 0 3 3 3 3 0 0 0 3 3 3 3 0 0 0 ]

Accedi per commentare.

Risposta accettata

David Hill
David Hill il 14 Giu 2022
a=[1 0 2 0 3 0 3 0];
d=4*(a>0)+3*(a==0);
n=repelem(a,d);

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by