I frequently use matlab on multiple adjacent computers running their own instances of matlab, and sometimes I want to share a trace or a title or an axis across figures in different computers.
I have third party software (search sharemouse or inputdirector for example) that enables clipboard sharing across multiple computers, so if there is any way that I can copy a figure element to the system clipboard and not just within the plot editing mode's internal version of the clipboard, i'll be good to go.
Perhaps a simpler problem that would be equally useful is if there is some way to copy an entire figure to the clipboard in a way that it can be pasted back into another instance of matlab, rather than as a bitmap for opening in word like the 'copy figure' option enables.
No products are associated with this question.
You can create a menu to copy the contents of a fig file as byte stream in the clipboard. Simply create a FIG file by hgsave, import the contents by fread and copy the data as string to the clibboard with a meaningful header:
[EDITED, code refreshed]
function FigClipboard(command, FigH) % Copy & paste a figure through the clipboard % Copy a figure: FigClipboard('copy', FigH) % Open a new copy: FigClipboard('paste') % % License: Copy, modify, use like you want.
file = fullfile(tempdir, 'FigForClipboard.fig'); magic = '$FigToClipboard$'; switch command case 'copy' % if nargin == 1 FigH = gcf; end hgsave(FigH, file); fid = fopen(file, 'r'); stream = fread(fid, Inf, 'uint8'); fclose(fid); clipboard('copy', [magic, sprintf('%02x', stream)]); delete(file);
case 'paste' str = clipboard('paste'); if ischar(str) && strncmp(str, magic, length(magic)) fid = fopen(file, 'w'); if fid == 1 error('Cannot open file for writing: %s', file); end
stream = sscanf(str(length(magic) + 1:end), '%2x'); fwrite(fid, stream, 'uint8'); fclose(fid); openfig(file); end end
There must be a function which avoids the indirection over the hard disk. FIG files have the same format as MAT files and they contain a struct only. So it should be possible to re-create the figure directly from this struct instead from writing a file. But I do not find these methods directly and the additional speed is nice, but not a must-have.
For the last part you could consider saving the figure as .fig and then copy the file to the other computer. Here you can open de figure with full compatibility and all data preserved.
To display certain parameters of the figure you can use the get function. For example for getting the title you use:
The inner 'get' retrieves the title of the current axes ('gca'). The outer 'get' converts it to a string.
In case you have more figures open then you have to have the axes-handle of figure-handle for the right figure but this is a bit more complicated. If you need that too, just let me know.
Play games and win prizes!Learn more