How do i generate 10 random matrix and store them?

4 views (last 30 days)
I want to generate 10 random matrix ,H_AB ,and store them in to H_AB_store ,here is my original code
At=7;
Br=2;
rw=10
H_AB_store=zeros(Br*rw,At*rw)
for i=1:rw
H_AB = sqrt(1/2)*[randn(Br,At) + j*randn(Br,At)];
H_AB_store(Br*i,At*i)=H_AB
end
However,the window always told me this error
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in unit_channel (line 7)
H_AB_store(Br*i,At*i)=H_AB
How do i modify this error?

Accepted Answer

Bhaskar R
Bhaskar R on 5 Nov 2019
You can perform this using multi dimentional(here say rw = 10) array or cell array(prefered when random matrix size not consistant each loop)
All 10 random matrices have same size so multi dimentional array usage is recommended
At=7;
Br=2;
rw=10;
H_AB_store=zeros(Br, At, rw);
for i=1:rw
H_AB_store(:, :, i) = sqrt(1/2)*[randn(Br,At) + i*randn(Br,At)];
end
You can access each matrix indexing as H_AB_store(:, :, 1), H_AB_store(:, :, 2),.. H_AB_store(:, :, 10) for random matrices

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!