How to store a matrix, A, in variable X, where X is also carrying a counter "i"

1 次查看(过去 30 天)
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.

采纳的回答

Ulli Srinivasu
Ulli Srinivasu 2020-9-16
Hi Neeraj,
simply create a structure.
X = struct();
X(i).A = A;
  3 个评论

请先登录,再进行评论。

更多回答(1 个)

Sindar
Sindar 2020-9-16
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:
n=10;
m=4;
X_new = rand(n,m);
for ind=1:10
X_old = X_new;
X_new = X_old.^2;
end
  4 个评论
Walter Roberson
Walter Roberson 2020-9-16
What you are seeing displayed is not two matrices, it is a way to represent a multidimensional matrix of numeric values on the command window.
I would suggest that you use SIndar's X_old strategy.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by