Why the 2nd code does not behave like the 1st code?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Askic V
le 3 Mar 2023
Modifié(e) : Askic V
le 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
Plus de réponses (1)
Askic V
le 27 Fév 2023
Modifié(e) : Askic V
le 27 Fév 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 commentaires
Voir également
Catégories
En savoir plus sur Antennas, Microphones, and Sonar Transducers dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!