Azzera filtri
Azzera filtri

Incorrect dimensions for matrix multiplication.

84 visualizzazioni (ultimi 30 giorni)
Could anyone help, please with explanation?
V=1+((exp(-0.5*t))*((-0.9)*(cos(1.323*t))-(0.34)*(sin(1.323*t))));
Error using *
Incorrect dimensions for matrix multiplication. Check that the number
of columns in the first matrix matches the number of rows in the
second matrix. To perform elementwise multiplication, use '.*'.
Thank you in advance.

Risposta accettata

Walter Roberson
Walter Roberson il 5 Ott 2019
((exp(-0.5*t))*((-0.9)*(cos(1.323*t))
The left side of the * operator is the same size as t is.
The right side of the * operator is also the same size as t is.
The * operator is algebraic matrix multiplication, also called "inner product" . For two matrices A*B, the rule is that size(A,2) must be the same as size(B,1) and that the output is size(A,1) by size(B,2) . For example you can * together a 4 x 3 matrix and a 3 x 1 matrix and get a 4 x 1 result.
Consider something the same size as t * something the same size as t. For it to be valid, then the second dimension of the first operand, which is size(t,2), must equal the size of the first dimension of the second operand, which is size(t,1) . So size(t,1) == size(t,1) must be true. That is only true if t is a square matrix.
Chances are that your t is not a square matrix, and is instead a 1 x something vector. 1 x N * 1 x N is not valid matrix multiplication.
If you want to multiply corresponding elements of ((exp(-0.5*t))*((-0.9) and (cos(1.323*t)) then that is referred to as "elementwise multiplication", and as indicated in the error message, that is the .* operator instead of the * operator.
((exp(-0.5*t))*((-0.9).*(cos(1.323*t))

Più risposte (1)

PROSPER
PROSPER il 9 Lug 2024 alle 9:10
Modificato: Torsten il 9 Lug 2024 alle 9:17
% Parameters
M = 50; % Number of antennas
K = 3; % Number of terminals
L_prime = 9; % Number of paths
SNR_dB = 20; % SNR in dB
numSymbols = 1000; % Number of QPSK symbols to transmit
% Convert SNR from dB to linear scale
SNR_linear = 10^(SNR_dB / 10);
% Generate random QPSK symbols for each terminal
data = randi([0 3], K, numSymbols); % QPSK symbols
qpskMod = exp(1j * pi/4 * (2*data + 1)); % QPSK modulation
% Channel matrix
H = (1/sqrt(2*L_prime)) * (randn(M, K, L_prime) + 1j*randn(M, K, L_prime));
% Transmit the symbols through the channel with L' paths
rxSignal = zeros(M, numSymbols);
for l = 1:L_prime
rxSignal = rxSignal + sqrt(1/L_prime) * H(:,:,l) * qpskMod;
end
% Add noise
noise = (1/sqrt(2*SNR_linear)) * (randn(M, numSymbols) + 1j*randn(M, numSymbols));
rxSignalNoisy = rxSignal + noise;
% MRC Receiver
H_combined = sum(H, 3); % Sum the channel gains over the L' paths
mrcWeights = H_combined';
size(mrcWeights)
ans = 1x2
3 50
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
size(rxSignalNoisy)
ans = 1x2
50 1000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
mrcSignal = mrcWeights .* rxSignalNoisy; % Elementwise multiplication
Arrays have incompatible sizes for this operation.
% ZF Receiver
zfWeights = pinv(H_combined);
zfSignal = zfWeights * rxSignalNoisy;
% Constellation diagrams
figure;
subplot(1, 2, 1);
plot(real(mrcSignal(:)), imag(mrcSignal(:)), 'o');
title('Constellation Diagram (MRC)');
xlabel('In-Phase');
ylabel('Quadrature');
grid on;
axis([-2 2 -2 2]);
subplot(1, 2, 2);
plot(real(zfSignal(:)), imag(zfSignal(:)), 'o');
title('Constellation Diagram (ZF)');
xlabel('In-Phase');
ylabel('Quadrature');
grid on;
axis([-2 2 -2 2]);
sgtitle('Constellation of Estimated Symbols for K=3, M=50, L''=9, \rho=20 dB');
  2 Commenti
PROSPER
PROSPER il 9 Lug 2024 alle 9:11
check these codes and correct them for me
Torsten
Torsten il 9 Lug 2024 alle 9:19
To use elementwise multiplication, both arrays have to be of the same size. This is not the case here (see above). Maybe you mean matrix multiplication:
mrcSignal = mrcWeights * rxSignalNoisy; % Matrix multiplication
This would work.

Accedi per commentare.

Tag

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by