Construct a vector from another, but add 2 values every 10 iteration
Mostrar comentarios más antiguos
Hello !
I would like to create a vector B from a vector A, and at every 10th iteration, implement 2 times the same value from A:
A = linspace(0,1,811);
B = [];
for i = 1:1:length(A)
if mod(i,10) ~= 0
B = [B,A(1,i)];
elseif mod(i,10) == 0
added_value = A(1,i);
B = [B,added_value,added_value];
end
end
I know the length of the vector B should be around 901. I should have 90 "added_values", but when I verify it I have almost 1000 of them.
And it seems at every iteration the "if" condition just skips to the "elseif" part... What should I do to make this work ? I can't think of any other method...
Thanks in advance !
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Performance and Memory en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!