Creating Planar array and computing value of each element using an equation and element coordinate location in millimeters
3 views (last 30 days)
Show older comments
I am creating an array of 23 (x-direction) X 23 (y-direction) unit cells. Each cell location needs to be defiend by its coordinate location in millimeters. Then using this x,y coordinate value to each cell and an equation, the value of each cell is computed and plotted against 360 degree color map. My code does not produce the required picture. The discritization seems incorrect as my array is not to scale of the required array.
x_v = zeros(23,1);
y_v = zeros(23,1);
for i=1:23
x_v(i)=1e-3*(4.5 + 9*(i-1));
y_v(i)=1e-3*(4.5 + 9*(i-1));
end
% phase profile equation
fo=10e9;
lambda= 3e8/fo;
ko= 360/lambda;
theta_i=0;
phi_i=0;
theta_r=25;
phi_r=30;
M = zeros(23,23);
for j=1:23
for i=1:23
M(j,i) = mod(-ko*(x_v(j)*(sind(theta_i)*cosd(phi_i)+sind(theta_r)*cosd(phi_r)) ...
+y_v(i)*(sind(theta_i)*sind(phi_i)+sind(theta_r)*sind(phi_r))),360);
end
end
imagesc(M)
colormap(jet)
colorbar
My result is this,
What is actually required is this,
Secondly, If I want to have different number of cells in x and y axis of array then how to ensure x cells are plotted on x axis of figure and y cells on y axis, in my case they get inverted i.e x cells are plotted on y-axis and vice versa?
0 Comments
Accepted Answer
Aishwarya
on 7 Nov 2023
Hi Shahid,
As per my understanding, you wish to seek clarification on how to get the expected result from the code provided while plotting the colormap.
After reviewing the code, consider changing the variable from “M(j,i)” to “M(i,j)” in the nested “for” loop as shown below:
for j=1:23
for i=1:23
M(i,j) = mod(-ko*(x_v(j)*(sind(theta_i)*cosd(phi_i)+sind(theta_r)*cosd(phi_r)) ...
+y_v(i)*(sind(theta_i)*sind(phi_i)+sind(theta_r)*sind(phi_r))),360);
end
end
I hope this resolves your questions as making the above change also ensures x cells and y cells are plotted on X and Y axis respectively.
I would also like to suggest some optimization for the code to perform the same tasks using “meshgrid” function. “meshgrid” function creates a 2-D grid of the required values on X and Y-axis and eliminates the need to use “for” loops. Consider the below example implementation:
% Define the x and y coordinates
x_v = 1e-3*(4.5 + 9*(0:22));
y_v = 1e-3*(4.5 + 9*(0:22));
% Create a grid of coordinates
[X, Y] = meshgrid(x_v, y_v);
% Compute the values of each cell
M = mod(-ko*(X.*(sind(theta_i)*cosd(phi_i)+sind(theta_r)*cosd(phi_r)) ...
+Y.*(sind(theta_i)*sind(phi_i)+sind(theta_r)*sind(phi_r))),360);
% Plot the result
imagesc(M)
colormap(jet)
colorbar
Please refer to below MathWorks documentation for more information on “meshgrid” function: https://www.mathworks.com/help/matlab/ref/meshgrid.html
I hope this helps!
More Answers (0)
See Also
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!