Error using * Incorrect dimensions for matrix multiplication.
이전 댓글 표시
i got a problem on line 30. what should i do?
답변 (1개)
Walter Roberson
2023년 5월 23일
zf_rate2(i_snr, i_users) = log2(1 + abs(w_zf' *curr_channel).^2/noise_var);
w_zf is 1 x 4. w_zf' is 4 x 1.
curr_channel is 4 x 1
You cannot * a 4 x 1 with a 4 x 1.
It looks like you are expecting to end up with a scalar, which suggests you want 1 x 4 * 4 x 1. So perhaps do not do the ' operation -- or perhaps us conj(w_zf) instead of w_zf'
conjugate or not does matter in this situation as both of your matrices are complex-valued.
댓글 수: 4
Alexander
2023년 5월 23일
Matrix multiplication (4x1) * (4x1) is not possible. Whether you use .* or you rearrange your matrices to (4x1) * (1x4), what ever you intention is.
Alexander
2023년 5월 23일
You can do what you want, Roberson is allways faster.
Joseph
2023년 5월 23일
Walter Roberson
2023년 5월 23일
curr_channel = channel(:, 1:n_users(i_users));
Your n_users does not just contain all ones. The second iteration, n_user(i_users) is 2, so you are selecting 2 columns into curr_channel making curr_channel a 4 x 2 matrix.
You use curr_channel in matrix multiplications with vectors of length 4 -- either 4 x 1 or 1 x 4. If you have arranged the orientation properly you can use 1 x 4 * 4 x n_users(i_users) which would give a 1 x n_users(i_users) result. But you are trying to assign that 1 x n_user(i_user) result to a scalar output location.
The problem cannot be fixed with numeric arrays, as you are wanting to store output arrays of different numbers of rows or columns depending on iteration. You will need to change to cell arrays... or change your calculation.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!