How to format my code in this way? Is there any shortcut?

56 visualizaciones (últimos 30 días)
dorian do
dorian do el 29 de Nov. de 2021
Respondida: Walter Roberson el 29 de Nov. de 2021
The code is been put in a block and is not executable, but the syntax is been highlighted. So I was wondering how could I do this, is there a shortcut that I can convert a block of code into this format.
  1 comentario
Walter Roberson
Walter Roberson el 29 de Nov. de 2021
Is the question about this Answers facility, or is it about the MATLAB editor?
Is the question about getting nice indentation?

Iniciar sesión para comentar.

Respuestas (3)

Image Analyst
Image Analyst el 29 de Nov. de 2021
Not sure what you mean, but to indent your code properly, and transfer it from MATLAB to your Answers post, do this
  1. In your MATLAB editor window type control-a, which will select the entire editor window (all lines of code).
  2. Type Control-i, which will properly indent all the code.
  3. If you want to paste it into an Answers post, then type control-c to copy the selected code in the clipboard
  4. In the Answers text box, type control-v to paste in the clipboard (paste in your lines of code copied from the MATLAB editor window)
  5. Make sure all the code is highlighted in Answers and click the Code icon to format it as code. This will allow it to have a little Copy button so people can seasily copy your code into the clipboard and paste it back into MATLAB so they can test run your code.
  2 comentarios
dorian do
dorian do el 29 de Nov. de 2021
sorry for being unclear, I updated my question with some explanation.
Image Analyst
Image Analyst el 29 de Nov. de 2021
I agree with Walter's comment below your original question. We still don't know what you mean by a block, and where this code is sitting (MATLAB or the Answers forum).

Iniciar sesión para comentar.


John D'Errico
John D'Errico el 29 de Nov. de 2021
If you put it in as a picture, then of course not!
However, if you paste in the code, then note there is a toolbar on top of the edit window when you are writing a comment or a question. Under that toolbar, you will see the word code. Does that give you a hint?
Next, click on this button in the code part of the toolbar, while you are editting.
You will see this appear in your edit window.
Now you can paste in any code you wish, into that spot. For example...
syms x
solve(x - 5 == 12)
ans = 
17
As you see, you can even tell it to evaluate that code in MATLAB.
  2 comentarios
Walter Roberson
Walter Roberson el 29 de Nov. de 2021
You need about 5 reputation to be permitted to run code in the Answers facility.
dorian do
dorian do el 29 de Nov. de 2021
sorry for being unclear, I updated my question with some explanation.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 29 de Nov. de 2021
If you are asking whether there is a keyboard shortcut for starting one of these "Code Example" blocks, then unfortunately the answer is NO.

Categorías

Más información sobre Interactive Model Editing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by