Starting a new line

조회 수: 122 (최근 30일)
1582251394
1582251394 2016년 3월 24일
댓글: Walter Roberson 2025년 3월 12일
Hi I'm really new to MATLAB. My questions is how to a start a new line without executing the code. For example if I have:
y = 1123414124124124124 (want new line here without executing)

채택된 답변

Meghana Dinesh
Meghana Dinesh 2016년 3월 24일
편집: Meghana Dinesh 2016년 3월 24일
Are you typing your code in the Command Window? Then use "..." and < enter >
But I suggest you start typing your code in a script. (Home > New > Script)
  댓글 수: 2
1582251394
1582251394 2016년 3월 24일
I have an incredibly long piece of code that only calculates one thing (in the worst way possible). I'm just trying to format it nicer. Thank you I will try out script and see if it helps.
Walter Roberson
Walter Roberson 2025년 2월 4일
Note that in modern versions of MATLAB, the "..." operator has an implied seperator before it.
In sufficiently old versions of MATLAB,
[123....
456]
would have been treated as 123.456. In modern versions of MATLAB, it is treated the same as
[123. ...
456]
and so would result in [123. 456]
Side note: the parsing of literal constants takes priority over the ... operator. Entering
[123...
456]
is treated as "123." followed by ".." which is a syntax error.
But
A = 123;
[A...
456]
would be treated as [A 456] which would be [123 456]

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Francis
Francis 2025년 3월 12일
Shift Enter rather than just Enter
  댓글 수: 1
Walter Roberson
Walter Roberson 2025년 3월 12일
Shift-Enter is especially valueable when entering commands at the command line, as it does indeed start a new line without executing everything that has been entered so-far.
Commands entered in this way can be recalled as a group in the command history, by pressing up-arrow to recall the last of the commands, and then pressing shift-uparrow to bring in each previous line.
However, shift-enter is treated just the same as enter within the editor.
shift-enter does not have the effect of "line continuation" . For example if you enter
a = 123 + 456<shift-enter>
- 789;
then that will be treated as two seperate commands, a = 123 + 456 and -789;

댓글을 달려면 로그인하십시오.


Andrew
Andrew 2025년 2월 4일
add ";" at the end, then click enter
  댓글 수: 1
Steven Lord
Steven Lord 2025년 2월 4일
That will end the current command (or end the current row, if it appears inside square brackets or curly braces to create a matrix or cell array.)
x = 12345; % This is one statement
y = [1 2; % This ends the first row of matrix y
3 4]
y = 2×2
1 2 3 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
z = {'apple'; % This ends the first row of cell array z
'banana'}
z = 2x1 cell array
{'apple' } {'banana'}
If you want to continue the command on the next line, using ... is probably the right thing to do.
q = 12345 + ... % Continue the statement on the next line
67890 % These two lines are the equivalent of "q = 12345 + 67890"
q = 80235
See this documentation page for more information on using ... and/or ; in MATLAB.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by