A MATLAB Warning Reported by the Code Analyzer — "Newline following comma acts as a row separator."

Jul. 21, 2025 • Updated Aug. 06, 2025

When creating a matrix in MATLAB, we should note that “Newline following comma acts as a row separator.” For example,

1
2
3
4
A = [1, 2, 3, 4, 
    5, 6, 7, 8];

A
1
2
3
A =
     1     2     3     4
     5     6     7     8

Which is equivalent to:

1
2
A = [1, 2, 3, 4;
    5, 6, 7, 8];

we can see MATLAB Code Analyzer reports a warning message about it:

image-20250721102551150

We can use the “line continuation” operator ...1 to not make a newline:

1
2
3
4
5
6
7
A = [1, 2, 3, 4, 
    5, 6, 7, 8];

B = [1, 2, 3, 4, ...
    5, 6, 7, 8];

A, B
1
2
3
4
5
6
A =
     1     2     3     4
     5     6     7     8

B =
     1     2     3     4     5     6     7     8

This point looks very trivial, but it will lead some errors about matrix size if we don’t mention it when coding — actually, recently I spent much time to find an error brought by making a newline but without using ....

Besides, the case is the same when omitting commas:

1
2
3
4
5
6
7
A = [1 2 3 4
    5 6 7 8];

B = [1 2 3 4 ...
    5 6 7 8];

A, B
1
2
3
4
5
6
A =
     1     2     3     4
     5     6     7     8

B =
     1     2     3     4     5     6     7     8


References