Main Content

grabcode

Extract MATLAB code from file published to HTML

Description

grabcode filename copies the MATLAB® code from the HTML file filename and pastes it into an untitled document in the Editor. Use grabcode to get MATLAB code from published files when the source code is not readily available. filename is the HTML file created by publishing a MATLAB code file (*.m) or exporting a live script (*.mlx) to HTML. In both cases, the MATLAB code from the file appears as HTML comments at the end of filename.

grabcode url copies MATLAB code from the page or file specified by url and pastes it into an untitled document in the Editor.

example

code = grabcode(filename) returns the MATLAB code from filename to a character array.

Examples

collapse all

Use grabcode to get MATLAB® code from an existing HTML file.

Extract the MATLAB code from my_sine_wave.html into the variable code. To view the contents of the file, double-click my_sine_wave.html in your current folder.

code = grabcode('my_sine_wave.html')
code = 
    '%% Plot Sine Wave
     % Calculate and plot a sine wave.
     
     %% Calculate and Plot Sine Wave
     % Calculate and plot |y = sin(x)|.
     
     function sine_wave_f(x)
     
     y = sin(x);
     plot(x,y)
     
     %% Modify Plot Properties
     
     title('Sine Wave', 'FontWeight','bold')
     xlabel('x')
     ylabel('sin(x)')
     set(gca, 'Color', 'w')
     set(gcf, 'MenuBar', 'none') '

Input Arguments

collapse all

Name of the HTML file, specified as a character vector or string scalar.

Example: grabcode('name.html')

Web page address or location of HTML file, specified as a character vector or string scalar.

Example: grabcode('https://www.mathworks.com/matlabcode.html')

Limitations

  • MATLAB Online™ only supports copying MATLAB code into a character array using the syntax code = grabcode(filename). Copying MATLAB code from an HTML page or file into an untitled document in the Editor is not supported.

Version History

Introduced before R2006a