Could anyone help me to solve with the following issue.

1 次查看(过去 30 天)
A=[20 40 60 80 100]
B= [ 120 140 160 180 200]
for t=1:length(A)
for r=1:length(B)
G=rand(A(t),B(r))
end
end
If i run the code it executes and I can see only (100x200) matrix in the workspace. Could anyone tell me how to view all sizes (20x120),(20,140),(20,160)...... in the workspace.
  1 个评论
Torsten
Torsten 2018-1-19
You permanently overwrite G in the above loop.
Only rand(A(5),B(5)) remains at last for G which is 100x200.
If you want to have matrices of sizes (20x120),(20x140) etc. in one structure, create G as cell(5).
Best wishes
Torsten.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2018-1-19
Probably the easiest way is to create ‘G’ as a cell array:
G{t,r} = rand(A(t),B(r));
Then you can address each element of the cell array to get the corresponding matrix to use later in your code.
  2 个评论
Prabha Kumaresan
Prabha Kumaresan 2018-1-19
If I use the command it gives me the size of the cell array. But how to get the data of each matrix with respect to rand command.
Star Strider
Star Strider 2018-1-19
Address the cell array with the appropriate subscripts to get the data in it:
UseMatrix = G{2,3};
will load the matrix in ‘G{2,3}’ into the ‘UseMatrix’ variable.
You can use the matrices in the cell array directly in your calculations. You do not have to load them to a separate variable first. (I am doing this here simply to demonstrate the idea.)

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by