Generate cell of random numbers with same size arrays
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Riccardo Zabatta
am 6 Mär. 2021
Kommentiert: Riccardo Zabatta
am 8 Mär. 2021
Hello!
I'd like to generate a 3x2 cell, whose arrays are all matrices 5x100 of random numbers.
I am a bit struggling with it, despite I think is quite easy to do.
Any suggestion?
Thanks
3 Kommentare
Jan
am 6 Mär. 2021
A a 3x2 cell with containing 5x100 matrices, a 15 x 200 random matrix is needed. Why do you create a 18x100 matrix?
Akzeptierte Antwort
Jan
am 6 Mär. 2021
Bearbeitet: Jan
am 6 Mär. 2021
Creating a large array only to split it into parts needs more RAM than creating the random matrices in parts directly:
C = cell(3, 2);
for k = 1:numel(C)
C{k} = randi(50, 5, 100);
end
If mat2cell is required for any reasons:
a = randi(50, 15, 200);
A = mat2cell(a, [5, 5, 5], [100, 100])
0 Kommentare
Weitere Antworten (1)
John D'Errico
am 6 Mär. 2021
Bearbeitet: John D'Errico
am 6 Mär. 2021
Simple enough.
A = rand(15,200);
B = mat2cell(A,repmat(5,3,1),repmat(100,1,2));
size(B)
size(B{1,1})
class(B{1,1})
So B is a cell array of size 3x2.
Each element of B is a regular double precision array, of size 5x100. You can put whatever you kind of random numbers you wish into the original array A.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!