필터 지우기
필터 지우기

Matrix dimensions must agree!!

조회 수: 20 (최근 30일)
Emmanuel
Emmanuel 2014년 10월 13일
답변: Ganesh P. Prajapat 2016년 6월 11일
Dear all,
I am preparing a matlab simulation to plot the output of an SMI adaptive beamformer algorithm, but i keep getting "matrix dimensions must agree" response, and i'm new to matlab and have not been able to fix this issue.
I am kindly asking for assistance.
Many thanks.
Here is the code:
N = 7;
l = 0:N-1;
fs = 12e6;
f = 1e6;
fi = 1e3;
SNR = 0;
INR = 10;
m = 8;
c = physconst('LightSpeed');
lambda = c/f;
d = lambda/2;
angles = -90:1:90;
theta = ([-pi/2,pi/2]);
phi = ([-pi,pi]);
j= sqrt(-1);
noisePwr = 0.5; % noise power
Ps = noisePwr*SNR; % signal power
A = Ps*10^(SNR/20);
I = 10^(INR/20);
s = A*exp(j*2*pi*f/fs*l);
i = I*exp(j*2*pi*fi/fs*l);
n = sqrt(noisePwr/2)*randn(m,l)+j*randn(m,l);
k = (2*pi)/lambda;
S = s';
a = exp(-j*2*pi*d*(0:m-1)'*sind(angles));%steering matrix
B = ctranspose(a);
input = a*S;
X = input + i + n;
r= (X*ctranspose(X))/N;
R = inv(r);
alpha = inv(B*R*a);
w = alpha*R*a; % weight vector
W = ctranspose(w);
Y = W*X;
plot (Y)
  댓글 수: 3
Emmanuel
Emmanuel 2014년 10월 14일
This is the error i'm getting in line 27.
Warning: Size inputs must be scalar. This will error in a future release. > In New at 22 Warning: Size inputs must be scalar. This will error in a future release. > In New at 22 Error using * Inner matrix dimensions must agree.
Error in New (line 27) input = a*S;
Stephen23
Stephen23 2014년 10월 14일
An Aside: don't use i, j and input as variable names, as these are the names of inbuilt functions in MATLAB. You can use which to identify any existing functions, or help for more information on these specific functions.

댓글을 달려면 로그인하십시오.

답변 (3개)

Ganesh P. Prajapat
Ganesh P. Prajapat 2016년 6월 11일
in line 27.. it should be >>input = a.*S as it requires term by term multiplication

Image Analyst
Image Analyst 2014년 10월 13일
Paste in ALL the red error text, don't snip out small chunk of it like you did. Most likely something is a vector or array that you thought was a single scalar number. Or you're using * to do a matrix multiply instead of .* to do an element-by-element multiply.
  댓글 수: 1
Image Analyst
Image Analyst 2014년 10월 14일
And what is the size of a and of S? Do this:
whos a
whos S
if a is m by n, then S must be n by p - the n's must be the same, that's just basic matrix math.
You might also look at this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ so you can solve these things yourself LOTS faster. Debugging by Answers forum always takes longer.

댓글을 달려면 로그인하십시오.


Stephen23
Stephen23 2014년 10월 13일

카테고리

Help CenterFile Exchange에서 Antennas, Microphones, and Sonar Transducers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by