Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use TeXShop instead of X11 for Matlab plots Apps
Matlab on OS X uses X11 to generate plots. These plots often have jagged lines, and are not rendered as smoothly as a PDF exported version of the same plot. With Octave, one can use the Aquaterm plotting front-end, but there seems to be no way to do that with Matlab. The following example piece of Matlab code makes Matlab convert a figure to PDF and display it in TeXShop, which auto-refreshes the PDF (unlike Preview):
figure(1);
set(gcf, 'Visible', 'off');
plot(x, y);
print(gcf, '-dpdf', 'figure1.pdf');
system('open -a Texshop figure1.pdf');
[robg adds: I can't test this one; if you can verify that it works, please post a comment.]
    •    
  • Currently 1.67 / 5
  You rated: 2 / 5 (3 votes cast)
 
[11,263 views]  

Use TeXShop instead of X11 for Matlab plots | 13 comments | Create New Account
Click here to return to the 'Use TeXShop instead of X11 for Matlab plots' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use TeXShop instead of X11 for Matlab plots
Authored by: vasisht on Apr 04, '05 10:28:31AM

Nice hint, plot looks much smoother than the default X11 plot in matlab.



[ Reply to This | # ]
Use TeXShop instead of X11 for Matlab plots
Authored by: azguy on Apr 04, '05 10:55:35AM

Indeed... works fine.



[ Reply to This | # ]
Use TeXShop instead of X11 for Matlab plots
Authored by: paperwings on Apr 04, '05 12:35:58PM

If you don't need to refresh the figure, Preview loads up dramatically faster (at least on my new powerbook).



[ Reply to This | # ]
Use TeXShop instead of X11 for Matlab plots
Authored by: paperwings on Apr 04, '05 12:37:53PM

Well..hmm. It did the first time. Now they seem about the same.



[ Reply to This | # ]
MatLab X11 plots are interactive
Authored by: googoo on Apr 04, '05 02:29:17PM

This is OK if the plot that you are generating is your final product, but you give up the interactive behavior of the MatLab X11 GUI plot interface, where you can change plot parameters by clicking on them. Furthermore, you can save plots to many formats, including PDF, from the X11 interface. Another file format available in MatLab is the MatLab figure file (.fig), which allows you to open a saved plot and reconfigure plot ranges, axis labels, etc. and even export to other file formats without regenerating the plot from your original data.

-Mark



[ Reply to This | # ]
MatLab X11 plots are interactive
Authored by: ennisdb on Apr 04, '05 03:18:52PM

I agree this is only relatively useful, but it points towards the ability to better interface Matlab and OS X. These things can be wrapped into an m-file to increase the usability. I previously wrote the following function to help me compare two m-files. I thought others might find it useful.


% This function sends an external call to FileMerge to compare two files a lá
% xdiff. If which(fname#) is empty (eg Matlab can't find it), then the fname#
% is assumed to be a full pathname (relative or absolute).
%
% SYNTAX: xdiff(fname1,fname2) OR xdiff fname1 fname2
%
% Place the following script in ~/bin and make it executable.
%
% #!/bin/sh
% /Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge -left $1 -right $2
%
% DBE 02/21/04
function xdiff(fname1,fname2);
tmp1=which(fname1);
if ~isempty(tmp1), fname1=tmp1; end % Assume the fname is a complete absolute or relative path if WHICH can't find it
tmp2=which(fname2);
if ~isempty(tmp2), fname2=tmp2; end % Assume the fname is a complete absolute or relative path if WHICH can't find it

cmmnd=['~/bin/xdiff ',fname1,' ',fname2,' &'];
unix(cmmnd);
return



[ Reply to This | # ]
MatLab X11 plots are interactive
Authored by: gustou on Apr 05, '05 08:04:23AM

What about a :
FileMergeApp = '/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge'

cmmd = sprintf('%s -left %s -right %s &', FileMergeApp, fname1, fname2);
unix(cmmnd);

This solution is a purely Matlab solution no ?



[ Reply to This | # ]
auto-refresh ?
Authored by: mag on Apr 04, '05 05:15:28PM

Indeed, the hint works fine. However, what do you mean by "auto-refreshes" exactly ? After the figure is in TexShop, if you modify it in Matlab (like putting a title, or scale units), it doesn't change in TexShop, you have to re-export the plot.
Or am I missing something ?
And in case I'm not wrong, then you're just telling us we can export Matlab plots as pdf and open them in any application we like that handles pdf, right ?



[ Reply to This | # ]
auto-refresh ?
Authored by: u2mr2os2 on Apr 04, '05 09:24:52PM

I think they mean that when you re-export the PDF, TexShop recognizes the file changed and then updates its display without you having to reload the PDF in TexShop.



[ Reply to This | # ]
auto-refresh ?
Authored by: shunker on Apr 05, '05 01:56:34AM

Yes, you need to re-export the figure with the print command, but then that line doesn't change, so if it pasted after the plot command, the PDF file is always current, and is then refreshed by TeXShop. As you said, the hint is nothing more than a way to print the figure to PDF and open it with a suitable viewer - I only wanted to emulate the similar behavior I was getting with Octave and Aquaterm.



[ Reply to This | # ]
Auto-refresh does not work for me
Authored by: hamarkus on May 23, '05 09:48:25AM

Just to let you know, I have to close the pdf file (in both cases using either Texshop or Preview) before I run the Matlab script again, otherwise it does not get updated, although the still-open pdf file is brought back in the foreground, creating the impression that it has been newly created and causing much agony on my side wondering why the hell Matlab is not adhering to any commands about the position of the figure on the page.

(Now judging from the length of the sentence, what is my mother tongue?)



[ Reply to This | # ]
Auto-refresh does not work for me
Authored by: cupertinox on Apr 06, '06 02:54:05PM

i can judge this even better from the pride that sounds through in your last comment. ha! erwischt.

anyway time that matlab offers an aquainterface on its own.



[ Reply to This | # ]
Use TeXShop instead of X11 for Matlab plots
Authored by: tpavlic on Jul 17, '07 01:26:45PM

Skim is probably a better alternative now.

It also autorefreshes from disk. It uses kqueue to do these updates, so they are event-based rather than updates resulting from polling the disk periodically. This is clearly a good way to do things, but the downside is that if the file gets deleted, updates will cease to be sent (e.g., what happens with simpdftex that can be easily fixed).

Regardless, it has lots of other great features. The author of the discontinued PDFView suggests that people use it instead. I think it will become the dominant PDF viewer in OS X.

Because it's simply a PDF viewer, it seems more appropriate (and probably opens faster) than using TeXShop for MATLAB previews.



[ Reply to This | # ]