Looking at your code:
A0=X(:,m);
A1=[X(:,m-1); A0];
A2=[X(:,m-2); A1];
A3=[X(:,m-3); A2];
A4=[X(:,m-4); A3];
A0 is the last column of X, A1 is the last two column of X (in one long vector), A2 is the last three column of X (shown in one long vector) and so on.
if you just want the last A, i.e. A4 or in case if X is (3x100) then A99 then all you need to do is:
or
otherwise, you could write a function like this:
function AN=getAN(X,n)
if (n<0 || n>(size(X,2)-1))
error('wrong n');
end
AN=reshape(X(:,end-n:end),[],1);
end
so now if you want A0
or if you want A4 do
you can do this in a loop as follow:
for n=0:4
A{n+1}=getAN(X,n);
end
NOTE: it is not a good idea to name your variabl A0, A1, ... Try to use cell, tables, arrays, and other structures.
Best Answer