Replace every nth element in a vector
36 views (last 30 days)
Show older comments
Maria Hart on 1 Feb 2021
Answered: Timo Dietz on 1 Feb 2021
I struggle with a rather simple question. I would like to generate a zero-vector with the length of the projectlength and then replace every xth value (which equals the lifetime) with the costs.
projectlength = 50;
costs = 30;
lifetime = 10;
Inv = zeros(projectlength,1);
I do not seem to get it right (Error message: Array indices must be positive integers or logical values.) although it is quite simple, I guess. Thanks for helping out!
Timo Dietz on 1 Feb 2021
You must not start your index with '0' but with '1'
More Answers (0)
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!