MATLAB: Addition to specified elements in a vector with for loop to create a new vector

for loopindexingvector

Hi all,
I am trying to add to specified elements in a vector to create a new one with the new values, however, unfortunately I could not make it…
The addition has been made to all the elements!
clear all;
x=[-7.5 -2.5 2.5 7.5] %
for i=1:3
xx(1,i)=2.5+x(i) % I need the 2.5 added only to [-7.5 -2.5 2.5] and also I need the output to be with the original vector included
% I mean I'd like the output to be
% xx(1,i)= [-7.5 -5 -2.5 0 2.5 5 7.5]
% I know i only = 3 and I need the output to be 9 elements but what can I do ??
end

Best Answer

xx=[x(1:3);x(1:3)+2.5];
xx=[xx(:)',x(4:end)];