How can I take a screenshot of a certain amount of code lines?

37 vues (au cours des 30 derniers jours)
Riccardo Basile
Riccardo Basile le 22 Jan 2019
Commenté : Riccardo Basile le 22 Jan 2019
Supposing my code was this
% hello
% it's me
% I'm batman
a = 1;
b = 2;
% hello world
% don't know what else to write
how can I take a screenshot of the lines from 3 to 5 for example? If this was possible it would be handy for writing documents where code needs to be shown.
  2 commentaires
John D'Errico
John D'Errico le 22 Jan 2019
Why do you think you need a screenshot? Code is text based. Text copies and pastes VERY easily. It takes less space to store than an image. It is editable. You can set fonts, colors, etc.
Just stick with text.
Riccardo Basile
Riccardo Basile le 22 Jan 2019
True, but I'd like to copy lines' numbers as well. It seems impossible to do using copy-paste; I'd need to write them manually which is kind of time consuming.

Connectez-vous pour commenter.

Réponses (1)

Steven Lord
Steven Lord le 22 Jan 2019
Consider writing your code in the Live Editor. Documents in the Live Editor can include both the code and the outputs from running that code in one report. The publishing functionality may be of interest if you want to send a document with code and outputs to someone who doesn't have MATLAB.
If you just want to display a subset of the lines in the file, you can use the dbtype function. That will display the lines as text rather than taking a screenshot of the Editor/Debugger section containing those lines, but perhaps that's sufficient for your needs.
  1 commentaire
Riccardo Basile
Riccardo Basile le 22 Jan 2019
I can't use Live Editor in this case since I need to include code pictures in an Office Word document. I've just tried the dbtype function; if it displayed the code preserving the colors (blue for "for" and "if" structures, magenta for strings and so on) it would be perfect. If these are the only options though, I think the default Windows "Snipping Tool" will do the job. Thanks a lot!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by