Could anyone help me to solve with the following issue.

1 view (last 30 days)
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 Comment
Torsten
Torsten on 19 Jan 2018
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.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 19 Jan 2018
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 Comments
Prabha Kumaresan
Prabha Kumaresan on 19 Jan 2018
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 on 19 Jan 2018
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.)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!