Fill a vector with zeros
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a vector difined as:
n=n1:n2
I want to make another vector of the same size as n called x, but with just a n0 value, and the others as zeros. Example:
n0=1
n1=-2
n2=2
So the vector n will be n = [-2 -1 0 1 2] and the x vector should be: x = [0 0 0 1 0]
Any idea aboud how can I do that?
0 comentarios
Respuestas (2)
Star Strider
el 9 de Nov. de 2015
One approach:
n0=1;
n1=-2;
n2=2;
n=n1:n2;
nz = zeros(size(n));
nz(n==n0) = n0
nz =
0 0 0 1 0
2 comentarios
Star Strider
el 9 de Nov. de 2015
If you want every value of the new vector to be ‘n0’, the new vector becomes:
nz = ones(size(n))*n0;
Please give an example of what you want if it is something other than what I describe here.
Ver también
Categorías
Más información sobre Spline Postprocessing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!