Reading a vector in intervals of 40.

2 次查看(过去 30 天)
Hi. Good day.
I would like to help me in the following:
I have a vector A
A = [14 8 12 18 8 34 24 14 12 22 2 20 2 10 16 8 10 18];
I want to add 0 to the first vector element A; 0 + 14 = 14
__ to the second element add 40; 40 + 8 = 48
__ to the third element add 80; 80 + 12 = 92
__ to the fourth element add 120; 120 + 18 = 138
__ to the fifth element add 160; 160 + 8 = 168
and so on (40 by 40).
I have tried with " for " cycles and I have not been able to do it.
In the end the searched vector would be:
[14 48 92 138 168 234 264 294 332 422 442 500 522 570 616 648 690]
Thank you

采纳的回答

Walter Roberson
Walter Roberson 2019-10-2
A = [14 8 12 18 8 34 24 14 12 22 2 20 2 10 16 8 10 18];
A + (0:length(A)-1) * 40
A + (0:40:40*(length(A)-1))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by