Looking at your code:
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:
otherwise, you could write a function like this:
if (n<0 || n>(size(X,2)-1))
so now if you want A0
or if you want A4 do
you can do this in a loop as follow:
NOTE: it is not a good idea to name your variabl A0, A1, ... Try to use cell, tables, arrays, and other structures.