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

53 ビュー (過去 30 日間)
dorian do
dorian do 2021 年 11 月 29 日
回答済み: Walter Roberson 2021 年 11 月 29 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 11 月 29 日
Is the question about this Answers facility, or is it about the MATLAB editor?
Is the question about getting nice indentation?

サインインしてコメントする。

回答 (3 件)

Image Analyst
Image Analyst 2021 年 11 月 29 日
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 件のコメント
dorian do
dorian do 2021 年 11 月 29 日
sorry for being unclear, I updated my question with some explanation.
Image Analyst
Image Analyst 2021 年 11 月 29 日
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).

サインインしてコメントする。


John D'Errico
John D'Errico 2021 年 11 月 29 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 11 月 29 日
You need about 5 reputation to be permitted to run code in the Answers facility.
dorian do
dorian do 2021 年 11 月 29 日
sorry for being unclear, I updated my question with some explanation.

サインインしてコメントする。


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

カテゴリ

Help Center および File ExchangeInteractive Model Editing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by