Decrease time in plotting the graph
조회 수: 4 (최근 30일)
이전 댓글 표시
% This code is to make a sparse matrix of the roof, from where the light can come
% in the receiver (Rx). This code would work for receiver at any position, orientation, field of view, etc.
clear;clc;
t0 = tic;
% ----------------Dimensions of the room------------------------------------------
length = 10.0; % Length of Room [m]
breadth = 10.0; % Breadth of Room [m]
height = 5.0; % height of Room [m]
% ---------------------------------------------------------------------------------
% -----------------Characteristics of Transmitter/Source - LED--------------------
n = 4; % Number of LEDs is given by
LED_VA = 60.0; % <Find out what is it called> ????
Ntx = [0 0 -1]; % Normal to the Tx's plane (Orientation)
% Let the position of Tx be Pos_Tx
i=0; j=0; k=5;
Pos_Tx = [i j k];
% ---------------------------------------------------------------------------------
% ----------------Characteristics of Receiver - Photodiode-------------------------
Rtx = [0 0 1]; % Normal to the Rx's plane (Orientation)
Rx_FOV = 36.0; % FOV (field of view)
psi_c = (Rx_FOV*pi)/180; % FOV (field of view) in Radians
% Let the position of Rx be Pos_Rx
Pos_Rx = [5 5 0];
% ---------------------------------------------------------------------------------
space = 0.5;
LOS = zeros(max(size(0:space:length)), max(size(0:space:breadth)));
toc(t0)
hold on;
t1 = tic;
r=1;s=1;
for i=0:space:length
r=1;
for j=0:space:breadth
Pos_Tx = [i j k];
% ---------------------------------------------------------------------------------
DD_Tx_Rx = Pos_Rx - Pos_Tx; % Direction from Tx to Rx
DD_Rx_Tx = -1*DD_Tx_Rx; % Direction from Rx to Tx
% Distance between Tx and Rx
R = sqrt((Pos_Tx(1,1) - Pos_Rx(1,1)).^2 +(Pos_Tx(1,2) - Pos_Rx(1,2)).^2 +(Pos_Tx(1,3) - Pos_Rx(1,3)).^2);
% Angle between orientation of Tx and direction of Rx
Phi = acosd( dot(DD_Tx_Rx,Ntx)./(R.*(sqrt((Ntx(1,1)^2 + Ntx(1,2)^2 + Ntx(1,3)^2)))));
% Angle between orientation of Rx and direction of Tx
Psi = acosd( dot(DD_Rx_Tx,Rtx)./(R.*(sqrt((Rtx(1,1)^2 + Rtx(1,2)^2 + Rtx(1,3)^2)))));
phi = (Phi*pi)/180; % Angle of irradiance (phi) in Radians
psi = (Psi*pi)/180; % Angle of incidence (psi) in Radians
% ---------------------------------------------------------------------------------
% ----------------- For Direct Light ----------------------------------------------
% LOS (line of sight) propagation path channel transfer function - HLOS
if (psi>=0) && (psi<=psi_c) && (Phi<=LED_VA)
HLOS = 1.0;
elseif (psi>psi_c)
HLOS = 0.0;
elseif (Phi>LED_VA)
HLOS = 0.0;
elseif (Psi>Rx_FOV)||(Phi>Rx_FOV)
HLOS = 0.0;
end;
LOS(r,s) = HLOS;
% ---------------------------------------------------------------------------------
plot3(i,j,LOS(r,s),'.b');
r = r+1;
end;
s = s+1;
end;
grid on;
toc(t1)
Nothing much to understand in this code.
The main thing is that plot3 function is taking 75% (almost 2.5 sec.) of all time. Is there a better way to plot the function in much less time than that?
Any other idea for optimizing the code is welcome... Please help out. Thanks Nishant
댓글 수: 0
답변 (1개)
Daniel Shub
2012년 4월 8일
You are calling plot3 in your loops. You would probably be better off saving all the data and calling plo3 once.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!