Error using * Incorrect dimensions for matrix multiplication.
Mostrar comentarios más antiguos
i got a problem on line 30. what should i do?
Respuestas (1)
Walter Roberson
el 23 de Mayo de 2023
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 comentarios
Alexander
el 23 de Mayo de 2023
Matrix multiplication (4x1) * (4x1) is not possible. Whether you use .* or you rearrange your matrices to (4x1) * (1x4), what ever you intention is.
Alexander
el 23 de Mayo de 2023
You can do what you want, Roberson is allways faster.
Joseph
el 23 de Mayo de 2023
Walter Roberson
el 23 de Mayo de 2023
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.
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!