The for loop below runs over the third dimension (page) to fill the alpha array. Is it possible to vectorize this for loop?
alpha_i_h_t = NaN(N_i,N_t,N_draws);
for i = 1:N_draws
alpha_i_h_t(:,:,i) = e_i_h(:,i) + e_h * t;
end

댓글 수: 2

Torsten
Torsten 2022년 2월 28일
e_i_h(:,i) is a column vector. For e_i_h(:,i) + e_h * t to be defined, e_h * t must be a column vector or a scalar.
So how do you want to write a column vector into a matrix array alpha_i_h_t(:,:,i) ?
Bruno Luong
Bruno Luong 2022년 2월 28일
No Torsen because MATLAB auto-expansion.

댓글을 달려면 로그인하십시오.

 채택된 답변

Bruno Luong
Bruno Luong 2022년 2월 28일
편집: Bruno Luong 2022년 2월 28일

0 개 추천

e_i_h_reshape = reshape(e_i_h,N_i,1,N_draws);
alpha_i_h_t = e_i_h_reshape + e_h * t;

댓글 수: 3

Snoopy
Snoopy 2022년 2월 28일
Thank you very much.
Torsten
Torsten 2022년 2월 28일
And why do you need a three-dimensional array for a two-dimensional content ?
Or do I get something wrong ?
Bruno Luong
Bruno Luong 2022년 3월 1일
편집: Bruno Luong 2022년 3월 1일
The result is 3D, each page contains a matrix sum of column by row vector.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2022년 2월 28일

편집:

2022년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by