Error using * Incorrect dimensions for matrix multiplication.

Réponses (1)

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 commentaires

Matrix multiplication (4x1) * (4x1) is not possible. Whether you use .* or you rearrange your matrices to (4x1) * (1x4), what ever you intention is.
You can do what you want, Roberson is allways faster.
ok thank you sir for your wonder full answer. but when i correct the error based on your answer, line 26 creats another error. if i correct line 26, it may creat other error. so how do i solve this and incoming errors?
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.

Connectez-vous pour commenter.

Question posée :

le 23 Mai 2023

Commenté :

le 23 Mai 2023

Community Treasure Hunt

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

Start Hunting!

Translated by