Why this code the given error?
4 次查看(过去 30 天)
显示 更早的评论
close all; clear all; clc;
vec = @(MAT) MAT(:);
vecH = @(MAT) MAT(:).';
% M = 5;
M = 10;
N = 4;
% N = 10;
d = 0.5;
K = 3;
SNR_dB = 20;
steerVecT = @(ang) exp(1j*2*pi*d*[0:M-1].'*sin(vecH(ang)));
steerVecR = @(ang) exp(1j*2*pi*d*[0:N-1].'*sin(vecH(ang)));
angleGrid = [-80:1e-2:80].';
steerGrid = steerMatTR(deg2rad(angleGrid), steerVecT, steerVecR);
rng(222);
targetAngle = [-30, 0, 40].'+rand(K, 1);
A = ones(K, 1);
steerM = steerMatTR(deg2rad(targetAngle), steerVecT, steerVecR);
r = steerM*A;
noiseVar = r' * r / length(r) / db2pow(SNR_dB);
w = sqrt(noiseVar / 2) * (randn(size(r)) + 1j * randn(size(r)));
y = r+w;
lambda = 2*sqrt(M*N*log(M*N))*sqrt(noiseVar);
cvx_begin sdp quiet
variable x(N*M,1) complex
variable F(M*N,M*N) hermitian
minimize(norm(y-x))
subject to
[F, x; x', lambda^2]>=0
for idxN1 = 0 : 1 : N-1
for idxN2 = 0 : 1 : N-1
Ftmp = F(idxN1*M+1:idxN1*M+M, idxN2*M+1:idxN2*M+M);
for delta = -(M-1) : 1 : M-1
if ((idxN1==idxN2) && (delta==0))
sum(diag(Ftmp, delta)) <= 1/N;
else
sum(diag(Ftmp, delta)) == 0;
end
end
end
end
cvx_end
spectrumANM = abs(x'*steerGrid).^2;
spectrumANM = spectrumANM/max(spectrumANM);
figure; plot(angleGrid, spectrumANM);
% User defined function
function steerM = steerMatTR(targetAngle, steerVecT, steerVecR)
steerA = steerVecT(targetAngle);
steerB = steerVecR(targetAngle);
steerM = zeros(size(steerA, 1)*size(steerB, 1), length(targetAngle));
for idxK = 1 : 1 : length(targetAngle)
steerM(:, idxK) = kron(steerB(:, idxK), steerA(:, idxK));
end
After running the above code, it gives the following error:
Undefined function 'cvx_begin' for input arguments of type 'char'.
Error in main (line 32)
cvx_begin sdp quiet
Can anyone help me in this regard?
采纳的回答
the cyclist
2021-9-8
CVX is a third-party MATLAB toolbox (i.e. not from MathWorks), that you need to install according to their instructions. You need to go to their website to do that.
11 个评论
the cyclist
2021-9-12
@Sadiq Akbar, you won't be able to officially accept @Walter Roberson's. The reason is that I answered your original question (so you could accept that), but then you asked additional questions in the ensuing comments. Walter was kind enough to answer those additional questions in his comments, but unfortunately comments cannot be accepted or upvoted.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!