Incorrect dimensions for matrix multiplication.
92 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Walter Roberson
2019-10-5
((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))
0 个评论
更多回答(1 个)
PROSPER
2024-7-9
编辑:Torsten
2024-7-9
% 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)
size(rxSignalNoisy)
mrcSignal = mrcWeights .* rxSignalNoisy; % Elementwise multiplication
% 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 个评论
Torsten
2024-7-9
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!