Extract MATLAB code from file published to HTML
grabcode('name.html')
grabcode('urlname')
code = grabcode('name.html')
grabcode('name.html')
copies MATLAB® code
from the file name.html
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.
The file name.html
was created by publishing name.m
,
a MATLAB code file containing cells. The MATLAB code from name.m
is
included at the end of name.html
as HTML comments.
grabcode('urlname')
copies MATLAB code
from the urlname
location and pastes it into an
untitled document in the Editor.
code = grabcode('name.html')
gets MATLAB code
from the file name.html
and assigns it the variable code
.
This example illustrates how to use grabcode
to
get MATLAB code from an existing HTML file:
% Copy sine_wave_f.html and the images it includes % from the MATLAB examples directory to your % current folder: copyfile(fullfile(matlabroot,'help','techdoc','matlab_env',... 'examples','sine_wave_f.html'), 'my_sine_wave.html') copyfile(fullfile(matlabroot,'help','techdoc','matlab_env',... 'examples','sine_wave_f_01.png'), 'sine_wave_f_01.png') copyfile(fullfile(matlabroot,'help','techdoc','matlab_env',... 'examples','sine_wave_f_02.png'), 'sine_wave_f_02.png') % If you want to view the file, double-click my_sine_wave.html % in your current folder. % Extract the MATLAB code from sine_wave_f.html: code = grabcode('my_sine_wave.html')
MATLAB returns:
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')