MATLAB: How to store a matrix, A, in variable X, where X is also carrying a counter “i”

arraycounterindices don't matchindices errorindices not compatibleMATLABmatricesmatrixmatrix arraymatrix manipulationvariablevariables

I have a matrix A, which I want to store in a varaible X.
Now I can do,
X=A;
But the varaible is X is having a counter i, beacuse the value of X variable in one iteration will be used in the next iteration and so on.
So, it put a counter like this;
X(i)=A;
But, in the above line, the indices error – Unable to perform assignment because the indices on the left side are not compatible with the size of the right side – is shown.
What should be the correct syntax, plaease tell me.

Best Answer

Hi Neeraj,
simply create a structure.
X = struct();
X(i).A = A;