How to copy (to clipboard) only significant part of a plot in Matlab? - matlab

How to copy (to clipboard) only significant part of a plot in Matlab? Without that large gray margins Matlab loves so much?
Is it possible to populate clipboard from Matlab command line?

As far as programmatically populating the system clipboard with image data captured from a Matlab figure goes, you might try Yair Altman's, ScreenCatpture utility on the Matlab File Exchange:
screencapture('handle',gca,'target','clipboard');
It has a lot of options and will allow you to specify a region or an entire figure. It does require Java, i.e., it won't run in '-nojvm' mode. You can read more about it at Yair's Undocumented Matlab site.
Also, you can change the current figure's background color to white before copying it via:
set(gcf,'Color','w');

In the figure window, choose "edit" -> "Copy Figure".
It's equal to Ctrl+C on text, etc., but takes only the main part of the figure. So if you go to word, say, and press Ctrl+V, or RIght Click -> Paste, you will get only the main part of figure, without the gray margins you hate so much...

Related

Matlab: Export a figure made with myaa

I am trying to get better quality phase plots of complex functions made with the Complex Function Explorer of E. Wegert CFE. For this purpose I apply the Matlab anti-aliasing function myaa.m to the phase plots that are made with the CFEGUI.m. For the example screenshot of the result window below I used the setting myaa([8 8]) in the Matlab command window which means that the supersampling enlarge the figure 8x and then downscale it to 1/8 to get the original h x w.
As one can see the window of the figure has no operation icons or menu options for save or print. My question is what to do with such a figure (beside making screenshots)? Can I somehow use export-fig to save such a figure or load it in an image array and if yes, how?
It is also possible to use the setting myaa([8 1]) which results in a very large figure window that is larger than my screen (and has the unpleasant attribute that it can not be moved). It would be even better if such a whole figure could be saved (not only the visible part).
You can use getframe to grab current figure information in pixels.
However, while I do not know how this affects you, notice that MATLAB versions above 2014b (included) have already anti-aliasing. The code you linked seem to be from 2008, I am not 100% sure if it has become obsolete now.

Matlab figure saved as .eps appears in 'horizontal sections' when opened in Adobe Illustrator

I normally save my matlab figures as .eps and then make them better looking using Adobe Illustrator. This works for most figures but not all.
For example I plotted my data using the violin.m function from file exchange. When I save it as .eps and open it in Illustrator, I don't get an editable figure as I usually do. Instead, My figure appears chopped in horizontal sections, and all I can do is delete them (like in the figure below).
Is there anything I can do in either matlab or Illustrator to be able to edit the figure?
I don't need an .eps file, I just need to be able to edit it.
EDITS:
I tried #MattSchmatt's suggestion of using the print2eps function but I had the same problem.
Saving as .pdf doesn't solve the problem, because the image I get is not editable in Illustrator (plus, I also get the horizontal 'chunks').
A minimal, complete and verifiable example requires matlab, the violin function linked above and illustrator. But if it helps, here's the matlab code to produce a similar figure. I save by clicking on Figure -> save as. (But as I said above I tried the print2eps function and that was the same).
X = rand(100,6);
figure; violin(X)
I tried the following, didn't work either.
set(gcf, 'Renderer', 'painters')
As the author of the question suggests, I also wasn't able to export an editable (vectorized) .eps file into Illustrator. However, exporting it as .pdf does the trick. The 'fill' for the violin plots is weird, though, and has horizontal sections (perhaps something to do with the way the density estimate is being plotted?) all over. I was able to fix this and make the plots normal (with solid filled shades): select all the horizontal sections/chunks using the magic wand tool, and then increase opacity to 100% (it is set to 50 based on the exported file). Once all the required edits are made, export the file as .tiff and it seems to look fine. Hope this replicates, and thus helps! (my MATLAB version is 2016, and Illustrator version is the CS5)

Save figures EPS from Matlab P file without display

My function calls code from other functions I did not write those but I know what they do. One of them is .p Matlab file with obfuscated content.
I am doing batch processing of a number of files. I want to write the figures directly to file without display. So I can go through them separately.
Any ideas on how to achieve this.
Thanks!
Script to save matlab figures to a specified directory
The above link works but I still want to avoid displaying the figures at all. Directly print to file. But the work around can simply close all open figures after that loop.
In your script, as soon as you create the figure, set its visibility to off.
For example:
figure(28732);
set(28732,'visible','off'); %Now the figure is not shown
You can now work with the figure, plot, save etc, without the visual clutter or system overhead of displaying it.
If you want ALL of your figures to start without visibility, you can set the default property, as follows:
set(0,'DefaultFigureVisible','off').
This will cause all generated figures to be generated without visibility. (Note, this will be very confusing is you forget that this property is set.)
You should still close the figure as soon as possible in the script, as a part of good memory management.

Matlab figure contents lost while saving as eps/pdf

I have tried most of the usually used options (print(figr, '-depsc', 'cross_corr.eps');) to save a matlab figure as eps/pdf but each time I do it, the figure contents are saved partially and perhaps one quarter of it is lost.
I have shared the figure here: http://ge.tt/2ZrsdD02/v/0?c
Using the options such as the following save it completely but I prefer it save it directly inti eps/pdf:
print(figr, '-dpng', 'cross_corr.png');
The problem seems to be that you have very small values in the 'PaperPosition' property of the figure. Try changing them to the default ones,
set(figr, 'PaperPosition', [0.634517 6.34517 20.3046 15.2284])
and then apply your print(figr, '-depsc', 'cross_corr.eps').
I attach results on my computer without and with 'PaperPosition' correction (using GSview with bounding box showed):
Also, consider reducing font size to avoid overlapped text:
set(findobj('type','text'), 'Fontsize', 5)
If I first enlarge the figure size (by using the middle button on the top right), and then save it as eps, I get this: http://ge.tt/1Pv8YE02/v/0
The quality is very nice as compared to all other options and the content are also ok.
Its not possible to automate it through script?...

Saving GUI as .jpg in matlab

In matlab, I have created a GUI with several plots and edit boxes filled with text for an experiment with the bike. These plots and edit box values vary depending on the data I input (120 different sets). I was able to save the GUI as a figure with
saveas(handles.speedbike,fullfile(savename), 'fig');
Speedbike is the handle I gave to one of the plots and savename is the name that the figure is saved under, which changes with each set.
Now I also wish to save all the sepparate GUI's as jpegs, but using the same code as above, but with 'jpg' instead of 'fig' only saves a small corner of the figure as a jpeg, not the whole GUI.
Is there any function that I can use to correctly save a gui as a jpeg, or any way to open a .fig file, and then saving a copy of that as a jpeg.?
You need to use the handle of the whole figure for your GUI, instead of the handle of one of the plots. You probably also want to use print for saving to jpg.
Ive found satisfactory results with this:
hg=get(0,'Children');
saveas(hg,'.\gui.fig','fig');
optsave.Format='png';
hgexport(hg,'.\gui.png',optsave);
Why this do not work?. This normally do with normal figures, and failed with GUI's:
optsave.Format='meta';
hgexport(hg,'.\gui.wmf',optsave);