AnttiLehikoinen

Matlab export to pdf (TMag)

Mar 29th, 2016
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.25 KB | None | 0 0
  1. function [] = save2pdf_TMAG3(fig_handle, ax_handle, fileName)
  2.  
  3. dir_Tikz = 'C:\Antti\Matlab\General Useful Stuff\Matlab2Tikz';
  4. dir_MikTex = 'C:\Antti\MikTex portable\miktex\bin';
  5. name_tex = 'makefigure_tmag_1a';
  6.  
  7. %trying to set legend position
  8. l_handle = findall(fig_handle,'Type','legend');
  9. if ~isempty(l_handle)
  10.     lPos = l_handle.Position(1:2);
  11.     axPos = ax_handle.Position(1:2);
  12.     axL = ax_handle.Position(3:4);
  13.     lPos = (lPos - axPos)./(axL);
  14.    
  15.     Lpos = [', at={(' num2str(lPos(1)) ',' num2str(lPos(2)) ')}, anchor=south west'];
  16. else
  17.     Lpos = [];
  18. end
  19.  
  20. %axis label sizes; legend position
  21. extraaxisoptions = ['xlabel style={font=\footnotesize},'...
  22.                        'ylabel style={font=\footnotesize},',...
  23.                        'legend style={font=\small' Lpos '},',...
  24.                        'ticklabel style={font=\scriptsize}'];
  25.  
  26. matlab2tikz('figurehandle', fig_handle, [dir_Tikz '\texfig.tex'], 'showinfo', false, 'width', '3.5in', 'extraaxisoptions', extraaxisoptions);
  27.  
  28. %compiling
  29. dirStr = ['cd "' dir_Tikz '"'];
  30. compileStr = ['"' dir_MikTex '\xelatex" -quiet "' dir_Tikz '\' name_tex '"'];
  31. system([dirStr ' & ' compileStr]);
  32.  
  33. %copying figure to destination
  34. copyfile([dir_Tikz '\' name_tex '.pdf'], fileName);
  35.  
  36.  
  37. end
Advertisement
Add Comment
Please, Sign In to add comment