Header

"So be wise as serpents and innocent as doves."

2015. május 30., szombat

Executing python scripts and cron jobs on raspberry pi

This command makes a file executable.
sudo chmod +x [filename]
This command opens up the setting window (time zone check and enabling ssh connection).
sudo raspi-config
Cron has different time zone sometimes than the system clock. By this command they can be synchronized.
sudo /etc/init.d/cron restart
Cron time dependent tasks can be set up in the log file that can be opened with:
crontab -e 
This command runs the python code (even if root privilege is required).
sudo python [filename]
Displays file and jumps to the end of it:
cat [filename]
Displays file one page at once:
pg [filename]
Returns local IP address.
hostname -I
Resets the root password.
sudo passwd root

2015. február 14., szombat

Phasor diagram in MATLAB


How to draw a phasor diagram in MATLAB?


function [value] = drawPhasors(Z)
%format bank
figure
hold on
Len = max(Z);
plot ([-Len, Len], [0,0]) %draw vertical line
plot ([0,0], [-Len, Len]) %draw horizontal line
axis ([-Len, Len,-Len, Len], 'square') %set axes
grid on
title('Phasor diagram')
xlabel('Real axis')
ylabel('Imaginary axis')
for k=1:length(Z) %for each number in array
myList = [real(Z(k)),imag(Z(k))];
arrow([0,0],[real(Z(k)),imag(Z(k))]) %plot phasor
%str = sprintf('%f+ %fj', real(Z(k)),imag(Z(k)));
%text(real(Z(k)),imag(Z(k)),str)
end
end

This function above takes an array of complex numbers and plots them on the Argand plane. Using multiple complex numbers it gives a phasor diagram.

The function drawPhasors uses Erik Johnson's arrow function. It can be downloaded here:
http://uk.mathworks.com/matlabcentral/fileexchange/278-arrow-m

I added Erik's function to my MATLAB path and I was able to use all of its nice properties.