Could anyone help me to solve with the following issue.

1 visualizzazione (ultimi 30 giorni)
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 Commento
Torsten
Torsten il 19 Gen 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.

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 19 Gen 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 Commenti
Prabha Kumaresan
Prabha Kumaresan il 19 Gen 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 il 19 Gen 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.)

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by