How to store a matrix, A, in variable X, where X is also carrying a counter "i"
2 views (last 30 days)
I have a matrix A, which I want to store in a varaible X.
Now I can do,
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;
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.
More Answers (1)
Sindar on 16 Sep 2020
Simple way: add a third dimension, "pages":
X(:,:,i) = A;
But, if you only need the last iteration, it's better to store just the current and last iteration. Something like:
X_new = rand(n,m);
X_old = X_new;
X_new = X_old.^2;