getting double plots in single

3 views (last 30 days)
SOHAN BISHT
SOHAN BISHT on 5 Jan 2022
Answered: Prachi Kulkarni on 10 Jan 2022
while plotting imagesc of the angle and the absolute of matrix E = [Ex Ey] , i am getting double plot in single window for each component .
clc;
clear ALL;
c = 3*10^8; lambda = 333*10^-9; w1 = c/lambda; w2 = 2*w1;
L=12;M=1000;dx=L/M;x=-L/2:dx:L/2-dx;y=x;
%T = 1000;dt= T/M; t = -T/2:dt:T/2-dt;
t = 3;
[X,Y] = meshgrid(x,y);
Ax = cos((pi/180)*(x + y));
Bx = 1i*sin((pi/180)*(x + y));
Ay = cos((pi/180)*(x - y));
By = 1i*sin((pi/180)*(x - y));
Ex = Ax + Bx.*exp(-1i*w1*t);
Ey = Ay + By.*exp(-1i*w2*t);
Em = [Ex Ey];
figure (1);
imagesc(x,x,abs(Em).^2);
figure (2);
imagesc(x,x,angle(Em).^2);

Answers (1)

Prachi Kulkarni
Prachi Kulkarni on 10 Jan 2022
Hi,
If Ex and Ey are the X and Y components and you want to compute the magnitude and phase, you can make some minor changes to your code as follows.
clc
clear all
c = 3*10^8; lambda = 333*10^-9; w1 = c/lambda; w2 = 2*w1;
L=12;M=1000;dx=L/M;x=-L/2:dx:L/2-dx;y=x;
t = 3;
% [X,Y] = meshgrid(x,y);
Ax = cos((pi/180)*(x + y));
Bx = 1i*sin((pi/180)*(x + y));
Ay = cos((pi/180)*(x - y));
By = 1i*sin((pi/180)*(x - y));
Ex = Ax + Bx.*exp(-1i*w1*t);
Ey = Ay + By.*exp(-1i*w2*t);
% Em = [Ex Ey];
figure (1);
magnitude = repmat(abs(Ex).^2,numel(x),1) + repmat((abs(Ey).^2)',1,numel(y));
% imagesc(x,y,abs(Em).^2);
imagesc(x,y,magnitude);
figure (2);
phase = atan(repmat((abs(Ey).^2)',1,numel(y))./repmat(abs(Ex).^2,numel(x),1));
% imagesc(x,y,angle(Em).^2);
imagesc(x,y,phase);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by