Sadiq Akbar asked . 2023-03-20

Why the 2nd code does not behave like the 1st code?

the code of "myfunAskMathworks.m", yo and ye both are of the order 36x1 and these are correct. But in the other  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.

myfunAskMathworks.m

u=[10 20 30 40];b=u;
M=6; % Tx constant
N=6; % Rx constant
d = 0.5; % constant
vecH = @(MAT) MAT(:).'; 
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))); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculation of yo and ye
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yo = yMatTR(deg2rad(u), steerVecT, steerVecR); % 36x1 in which 36 is due to M*N
ye = yMatTR(deg2rad(b), steerVecT, steerVecR); % 36x1 in which 36 is due to M*N
%%%%%%%%%%%%%%%%%%
% MSE
%%%%%%%%%%%%%%%%%%
e=norm(yo-ye).^2/(M*N);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function yMatTR
%%%%%%%%%%%%%%%%%%%%%%%%5%%%
function y = yMatTR(targetAngle, steerVecT, steerVecR)
   steerA = steerVecT(targetAngle); 
   steerB = steerVecR(targetAngle); 
   y=sum( steerA.*permute(steerB,[3,2,1]) ,2);
   y=y(:);   
end

codeWithArrays.m

close all; clear all; clc;
 u=[10 20 30 40];b=u;
az = u(1:2)'; %Azimuths
el = u(3:4)'; % Elevations
M = length(az); % No. of sources
 
L = 1;
m = randn(M,L); 
 
% Wavenumber vectors 
k = pi*[cosd(az).*cosd(el), sind(az).*cosd(el), sind(el)].';% Always 3 x No. of sources

% 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=6;
% 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

 
% Matrices AT and AR
AT = exp(-1j*rT*k);% Always (TX Antennas x No. of sources)
AR = exp(-1j*rR*k);% Always (RX Antennas x No. of sources)
az=az';
el=el';
yo = yMatTR(deg2rad(az), AT, AR); % 36x1 in which 36 is due to M*N
ye = yMatTR(deg2rad(el), AT, AR); 
%%%%%%%%%%%%%%%%%%
% MSE
%%%%%%%%%%%%%%%%%%
e=norm(yo-ye).^2/(M*N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function yMatTR
%%%%%%%%%%%%%%%%%%%%%%%%5%%%
function y = yMatTR(targetAngle, steerVecT, steerVecR)
   steerA = steerVecT(targetAngle); 
   steerB = steerVecR(targetAngle); 
   y=sum( steerA.*permute(steerB,[3,2,1]) ,2);
   y=y(:);   
end

 

error , how to make same r... , GIWAXS evaluation - scripting , matlabsolutions , matlab

Expert Answer

Prashant Kumar answered . 2024-05-14 09:55:06

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

 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.