Why this piece of code gives error?

When I run the following code, it gives me error on line 19. The code is:
clear;clc;
c = 3e8; % signal propagation speed
fc = 1e9; % signal carrier frequency
lambda = c/fc; % wavelength
thetaad = -30:5:30; % look directions
thetaan = [-40 40]; % interference direction
ula = phased.ULA(10,lambda/2);
ula.Element.BackBaffled = true;
% Calculate the steering vector for null directions
wn = steervec(getElementPosition(ula)/lambda,thetaan);
% Calculate the steering vectors for lookout directions
wd = steervec(getElementPosition(ula)/lambda,thetaad);
% Compute the response of desired steering at null direction
rn = wn'*wd/(wn'*wn);
% Sidelobe canceler - remove the response at null direction
w = wd-wn*rn;
% Plot the pattern
pattern(ula,fc,-180:180,0,'PropagationSpeed',c,'Type','powerdb',...
'CoordinateSystem','rectangular','Weights',w);
hold on; legend off;
The error is:
Error using /
Matrix dimensions must agree.
Error in abc (line 19)
rn = wn'*wd/(wn'*wn);

Antworten (1)

Anton Kogios
Anton Kogios am 28 Feb. 2023

0 Stimmen

Your multiplications in Line 19 give a 2 by 13 matrix in the numerator and a 2 by 2 matrix in the demoninator.
To perform matrix multiplication/division, you need the number of columns of the first to be equal to the number of rows of the second. So, a fix to your error may be this, but it depends what you are trying to do:
rn = (wn'*wd)'/(wn'*wn);

3 Kommentare

Thanks a lot for your kind response dear Anton Kogios. Actually I want to produce nulls in the following two directions:
thetaan = [-40 40]; % interference direction
Because when I make it single number i.e.,
thetaan = [40]; % interference direction
then it doesn't give me error and gives me plot at desired diorection of 40. But when I make it a vector like in the 1st case, then it gives me an error. How to rectify it for the 1st case i.e., if I want to get two nulls at directions -40 and 40 respectively?
Anton Kogios
Anton Kogios am 28 Feb. 2023
Sorry Sadiq, I wish I could help further but I am not too familar with the content of your question. Hopefully someone else is able to help out.
I did notice, however, that since you turn hold on, you can just run the code twice with each separate value, so maybe you can create a loop and function to meet your needs.
Sadiq Akbar
Sadiq Akbar am 28 Feb. 2023
Thanks a lot for your kind response dear Anton Kogios. Yes, you are right. May be someone else may help me out. Thanks once again.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 28 Feb. 2023

Kommentiert:

am 28 Feb. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by