Pages

Sunday, September 15, 2013

Plotting Matlab Figures and linking them to Latex

I am writing my thesis which means I need to do lots of latex! I am plotting figures in matlab but it is bit tricky linking matlab figures to latex!

So, here's the perfect way to get things done!

1. Plot all the data
2. Call tightfig script to remove margins (
http://www.mathworks.com/matlabcentral/fileexchange/34055)
3. Save the file in pdf
4. Plot in latex!

Example Latex:
\begin{figure}[!ht]
 \centering
 \includegraphics[scale=0.45]{Figures/Chap2/Fault_Profile.pdf}
 \caption{Different Fault Resistances.}
 \label{fig:fault_profile}
\end{figure}
 
 
Example Matlab Script:
%impedance from substation
            impedance=[3.781923798    5.435882686    6.368358163    7.200380563    9.856371439 9.856371439    15.87650559    ...
                16.51528666    16.70110783    17.13156594    17.32078243    18.51808337    21.08402126];
           
           
            voltage_data=[25.9532622445019,25.7653016067929,25.6691255616736,25.5853983811606,25.3569910635690,25.3569868192443,24.9617555108483,...
                24.8825781473615,24.8598716415630,24.8123234278547,24.7888762649503,24.6898624381824,24.6335180770592
               
                26.0814492943857,25.9799517244703,25.9265392586507,25.8813822264662,25.7550839588058,25.7550599002203,25.5310154073116,...
                25.4821039369688,25.4685035318285,25.4401241743564,25.4258036302699,25.3646712093259,25.3299030962158
               
                26.1764298329928,26.1514908385483,26.1386241507187,26.1273111091974,26.0969883677681,26.0969850365599,26.0397214690784,...
                    26.0234564651756,26.0187420587268,26.0089169654977,26.0040301248486,25.9831659832180,25.9712770752272
                ];
           
            fig=plot(impedance',voltage_data(1,:)','kv','markersize',10);
            hold on;
            plot(impedance',voltage_data(2,:)','b*','markersize',10);
            plot(impedance',voltage_data(3,:)','ms','markersize',10);
           
            plot(xlim',ones(1,2)*25,'-.','color','black');
            text(12,25,'25 kV','background','w');
           
           
            plot(xlim',ones(1,2)*25*1.058,'-.','color','black');
            plot(xlim',ones(1,2)*25*0.95,'-.','color','black');
            plot(xlim',ones(1,2)*25*1.05,'-.','color','black');
            plot(xlim',ones(1,2)*25*0.975,'-.','color','black');
            text(11,25*1.056,'Range B Upper Limit','background','w')
            text(11,25*0.95,'Range B Lower Limit','background','w')
            text(11,25*1.05,'Range A Upper Limit','background','w')
            text(11,25*0.975,'Range A Lower Limit','background','w')
           

            xlabel ('Impedance from substation (Ohms)')
            ylabel ('Voltage (kV)')
           
            title ('System voltage profile for different system loadings');
            legend ('100%','60%','20%','Location','SouthWest');
           
            hold off;
            tightfig;
            saveas(fig,'C:\Users\hcheem2\Dropbox\Thesis\Thesis_hcheema\Figures\Chap2\Voltage_Profile.pdf','pdf');





No comments:

Post a Comment