How can export my MATLAB figure encoding it in base64 format in MATLAB 7.7 (R2008b)?
3 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Commented: Walter Roberson
on 16 Mar 2017
I want to encode a figure in MATLAB 7.7 (R2008b) into a text representation to include inline within an XML document. Base64 seems a good candidate for this, however I can't find any native support for this encoding via PRINT or IMWRITE or any other exporting function in MATLAB. Is there any way to achieve this, via third party tools if necessary?
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
This feature is not available in MATLAB 7.7 (R2008b).
As a alternative, you might want to refer to the following external sources:
Data type and data conversion utilities
<http://home.online.no/~pjacklam/matlab/software/util/datautil/index.html>
base64decode - Perform base64 decoding on a string
base64encode - Perform base64 encoding on a string
Please understand that we can not guarantee or support third party products or functions, however customers have reported to successfully work with the above functions before. You also might be interested in the following source:
<http://www.wikihow.com/Encode-a-String-to-Base64-With-Java>
To convert the figure to a string you can print it to the desired image format (using the menu or PRINT command) and afterwards read it to a string using low level I/O functions (FOPEN, FREAD, FCLOSE). Note the following example:
function str64 = encodeFigure( h )
filename = 'encodeFigure.png';
if exist('h','var')
print(['-f' num2str(h)], '-r300','-dpng', filename );
else
print( '-r300','-dpng', filename );
end
fid = fopen( filename, 'r' );
im = fread( fid );
fclose(fid);
str64 = base64encode( im, [] );
delete(filename);
end
1 Comment
More Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!