How do i generate 10 random matrix and store them?

조회 수: 1 (최근 30일)
yang-En Hsiao
yang-En Hsiao 2019년 11월 5일
답변: Bhaskar R 2019년 11월 5일
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?

채택된 답변

Bhaskar R
Bhaskar R 2019년 11월 5일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by