MATLAB: Concatenate arrays in foor loop. Torque problem

arrayconcatenate

Torque problem
I'm trying to concatenate arrays in foor loop ta one Array containing all values.
The last value in Array Mloc are the same value as the first value in Mloc in the next loop so the first value in every loop should not be omitted (or the last)
say I have these
d= [0 0 0 0 0 0 0 0 0 0]
a = [0 5 8 7] b = [7 5 3 4] c = [4 5 2 6]
The result I want:
d = [0 5 8 7 5 3 4 5 2 6]
My code so far:
npl=1000; % x-Pos on beam where torque should be calculated
n=4; % number of fields
L=[3 6 2 5] % length of each field
j=0;
k=0;
Mbeam=zeros(n*(npl-1)+1,1); % preallocate memory for Array with torque values over entire beam
for i=1:n % loops over every field
j=k; % lower x-value on current field
k=j+L(i); % higher x-value on current field
x=linspace(j,k,npl)'; % creats npl x Points in current field
Mloc=MA(i) + RA(i).*x + (q(i).*(x.^2))./2; % Calculates an Array with the torque value in every x for ONE field
Mbeam=[Mbeam;Mloc];
% Here is the problem. As above i want to concatenate Mloc with Mbeam
without placing Mloc after all the zeros in Mbeam.
As discribed above I would also like to see to that the first value in Mloc during the second loop
overwrites the current last value in Mbeam making the total length of the final Mbeam = 3997
end
Most grateful for help.

Best Answer

Alexander
Stephen is right, solving your question is about using the indices correctly.
Have you considered using a cell for all your torques?
1.
a=[0 5 8 7]
b=[7 5 3 4]
c=[4 5 2 6]
A={a b c}
=
[1x4 double] [1x4 double] [1x4 double]
2.
to access each vector
A{1}
=
0 5 8 7
A{2}
=
7 5 3 4
A{3}
ans =
4 5 2 6
3.
to access a single element within a vector
A{1}(2)
=
5
4.
Concatenating vectors inside this cell
D=0;
for k=1:1:length(A)
L=A{k}([1:end-1]);
D=[D L];
end
5.
remove 1st element of D, and add the last element of the last concatenated vector
D(1)=[];
D=[D A{end}(end)]
D =
0 5 8 7 5 3 4 5 2 6
.
Christian
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG