# how can I increase the size of an incremental vector filling the space with zeros

5 visualizzazioni (ultimi 30 giorni)
Sarah Boukarras il 19 Giu 2022
Risposto: Image Analyst il 19 Giu 2022
Hi, I have an incremental vector of lenght 5
a = [1 5 8 11 14]
I want to stretch a and create a new vector of length 14 in which all the empty positions between the values of a are replaced by zeros
b = [1 0 0 0 5 0 0 8 0 0 11 0 0 14]
I have already tried interpolation but doesn't seem to work
Any suggestion is very much appreciated
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Abolfazl Chaman Motlagh il 19 Giu 2022
use ismember function.
X = cumsum(randi(3,1,5))
X = 1×5
1 3 5 7 10
Y = 1:X(end);
Y = ismember(Y,X).*Y
Y = 1×10
1 0 3 0 5 0 7 0 0 10
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Sarah Boukarras il 19 Giu 2022
Yes, that worked. Thanks a lot!!

Accedi per commentare.

### Più risposte (1)

Image Analyst il 19 Giu 2022
The accepted answer might work but I think it's complicated and the simpler answer is to just do this:
a = [1 5 8 11 14];
b(a) = a
b = 1×14
1 0 0 0 5 0 0 8 0 0 11 0 0 14
I mean, how much simpler could it be? If you like my answer, you can vote for it.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Loops and Conditional Statements 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