Could anyone help me to solve with the following issue.
1 view (last 30 days)
Show older comments
Prabha Kumaresan
on 19 Jan 2018
Commented: Star Strider
on 19 Jan 2018
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
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.
Accepted Answer
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
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.)
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!