Why the 2nd code does not behave like the 1st code?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
In the attached code of "myfunAskMathworks.m", yo and ye both are of the order 36x1 and these are correct. But in the other attached code "codeWithArrays.m", it gives error on line 35. Why is it so? In this also we should get the same order of yo and ye but it gives error.
0 Commenti
Risposta accettata
Askic V
il 3 Mar 2023
Modificato: Askic V
il 3 Mar 2023
This is how I would modified the code to execute for any M r N dimensions:
clear
clc
u = [10 20 30 40];
b = u * (1+0.5*randn); % random deviation between u and b
% Tx antennas
N = 6;
% Array geometry [rx,ry,rz] (example: uniform circular array)
radius = 0.5/sind(180/N);
rx = radius*cosd(360*(0:N-1).'/N);
ry = radius*sind(360*(0:N-1).'/N);
rT = [rx, ry, zeros(N,1)];% Always No. of Antennas x 3
% Rx antennas
M = 10;
% Array geometry [rx,ry,rz] (example: uniform circular array)
radius = 0.5/sind(180/M);
rx = radius*cosd(360*(0:M-1).'/M);
ry = radius*sind(360*(0:M-1).'/M);
rR = [rx, ry, zeros(M,1)];% Always No. of Antennas x 3
% rT is size Nx3, so to make multiplication work,
% [cos(alpha).*cos(beta); sin(alpha).*cos(beta); sin(beta)] must be 3x1
AT = @(alpha, beta) exp(-1j.*rT*pi*[cos(alpha).*cos(beta); sin(alpha).*cos(beta); sin(beta)]);
% rR is size Mx3, so to make multiplication work,
% [cos(alpha).*cos(beta); sin(alpha).*cos(beta); sin(beta)] must be 3x1
AR = @(alpha, beta) exp(-1j.*rR*pi*[cos(alpha).*cos(beta); sin(alpha).*cos(beta); sin(beta)]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculation of yo and ye
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yo = yMatTR(u, AT, AR);
ye = yMatTR(b, AT, AR);
%%%%%%%%%%%%%%%%%%
% MSE
%%%%%%%%%%%%%%%%%%
e=norm(yo-ye).^2/(M*N);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function yMatTR
%%%%%%%%%%%%%%%%%%%%%%%%5%%%
function y = yMatTR(targetAngle, steerVecT, steerVecR)
az = deg2rad(targetAngle(1:2));
el = deg2rad(targetAngle(3:4));
steerA = steerVecT(az,el);
steerB = steerVecR(az,el);
y=sum( steerA.*permute(steerB,[3,2,1]) ,2);
y=y(:);
end
Più risposte (1)
Askic V
il 27 Feb 2023
Modificato: Askic V
il 27 Feb 2023
It is because in the function "myfunAskMathworks.m" you have function handles defined. So, you are sending the function handle as an input parameter to the function yMatTR.
steerVecT = @(ang) exp(1j*2*pi*d*(0:M-1).'*sin(vecH(ang)));
In the line:
steerA = steerVecT(targetAngle)
you are actually calling the function handle for angles as an input to the function.
In the other file:
AT = exp(-1j*rT*k);
this is not a function, but an array (matrix) of complex numbers.
So in the line:
steerA = steerVecT(targetAngle);
you are trying to access elements of a matrix with indices that are not either integer or logical values.
Essentially, you are confusing function handles with matrices.
12 Commenti
Vedere anche
Categorie
Scopri di più su Antennas, Microphones, and Sonar Transducers in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!