# Delay and Sum example error

조회 수: 5 (최근 30일)
Dhananjay Singh 2019년 3월 7일
답변: Astha Singh 2019년 3월 14일
Hi, I'm very new to MATLAB and am having some trouble. I am running an example i found online but I am facing this problem. Could somebody please explain what this error is and how to fix it.
The code i am running is :
xPos = -0.8:0.2:0.8; % 1xP vector of x-positions [m]
yPos = zeros(1, numel(xPos)); % 1xP vector of y-positions [m]
zPos = zeros(1, numel(xPos));
elementWeights = ones(1, numel(xPos))/numel(xPos); % 1xP vector of weightings
% Define arriving angles and frequency of input signals
thetaArrivalAngles = [-30 10]; % degrees
phiArrivalAngles = [0 0]; % degrees
f = 800; % [Hz]
c = 340; % [m/s]
fs = 44.1e3; % [Hz]
% Define array scanning angles (1D, so phi = 0)
thetaScanAngles = -90:0.1:90; % degrees
phiScanAngles = 0; % degrees
% Create input signal
inputSignal = createSignal(xPos, yPos, zPos, f, c, fs, thetaArrivalAngles, phiArrivalAngles);
% Create steering vector/matrix
e = steeringVector(xPos, yPos, zPos, f, c, thetaScanAngles, phiScanAngles);
% Create cross spectral matrix
R = crossSpectralMatrix(inputSignal);
% Calculate delay-and-sum steered response
S = steeredResponseDelayAndSum(R, e, elementWeights);
%Normalise spectrum
spectrumNormalized = abs(S)/max(abs(S));
%Convert to decibel
spectrumLog = 10*log10(spectrumNormalized);
%Plot array
fig1 = figure;
fig1.Color = 'w';
ax = axes('Parent', fig1);
scatter(ax, xPos, yPos, 20, 'filled')
axis(ax, 'square')
ax.XLim = [-1 1];
ax.YLim = [-1 1];
grid(ax, 'on')
title(ax, 'Microphone positions')
%Plot steered response with indicator lines
fig2 = figure;
fig2.Color = 'w';
ax = axes('Parent', fig2);
plot(ax, thetaScanAngles, spectrumLog)
grid(ax, 'on')
ax.XLim = [thetaScanAngles(1) thetaScanAngles(end)];
for j=1:numel(thetaArrivalAngles)
indx = find(thetaScanAngles >= thetaArrivalAngles(j), 1);
line(ax, [thetaScanAngles(indx) thetaScanAngles(indx)], ax.YLim,'LineWidth', 1, 'Color', 'r', 'LineStyle', '--');
end
xlabel(ax, '\theta')
ylabel(ax, 'dB')
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The error that i face is :
Vectors must be the same length.
Error in examplesSteeredResponse
line(ax, [thetaScanAngles(indx) thetaScanAngles(indx)], ax.YLim,'LineWidth', 1, 'Color', 'r', 'LineStyle', '--');
Can somebody please tell me what should I do to reolve this issue.

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

### 답변 (1개)

Astha Singh 2019년 3월 14일
As the error is reported in the usage of the 'line()' command, you should refer to the documentation page of the same (link provided below), and see if the variables that are being plotted are in the expected form.
The 'line(x,y)' function requires the x and y co-ordinate values, it plots the variable 'y' against 'x'. Hence both should be of the same length. Please confirm that is also the case with the variables you are plotting.

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

### 카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by