Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Created July 22, 2014 22:25
Show Gist options
  • Select an option

  • Save tonyfast/694849fe97c8b8ca0734 to your computer and use it in GitHub Desktop.

Select an option

Save tonyfast/694849fe97c8b8ca0734 to your computer and use it in GitHub Desktop.
Load Plotly graph information directly to Matlab
function data = fromPlotly( url )
%% Import data from Plotly graphs into the matlab workspace using urlread.
% With ``fromPlotly`` in your path, call fromPlotly(url) where ``url`` is a
% link to a valid Plotly plot.
%% Example URI
% url = 'https://plot.ly/~TonyFast/4'
%% Loading in data to Matlab from a plot.ly link
% Append .m to url
url = horzcat( url, '.m' );
% Make a request to read the body
s = urlread( url );
% Remove html,pre tags
% Remove an apostrophe in in Open sans where the font family
s = strrep(strrep(strrep( ...
s, ... # html request
'<html><pre>',''), ... % Remove leading tags
'</pre></html>',''), ... % Remove trailing tags
'''Open sans''','Open sans'); % Remove apostrophe problem in string
% Evaluate the string as matlab commands
% The combined output is in the variable ``data``
eval( s );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment