Jump to navigation
Jump to search
← Older edit
Newer edit →
Octave style guide
Revision as of 16:30, 12 January 2017
1,456 bytes added
16:30, 12 January 2017
=== Variable names ===
== Quoted Strings ==
Always use double quotes for strings and characters rather than the Matlab single quote convention. Both quote types are accepted by Octave, but double quoted strings are interpreted slightly differently (see [https://www.gnu.org/software/octave/doc/interpreter/Strings.html Strings] in the manual for details).
a = "Hello, world";
b = "x";
disp ("This \"string\" contains a\nnewline");
s = 'Hello, world';
if (x(1) == 'c')
disp ('Don''t quote one character this way, even if you''re a C programmer');
There are a few edge cases where single quoted strings may be preferable, and are permitted as exceptions under this style guide.
; String containing double quotes
: A string that contains many double quote characters itself, where escaping all of them with backslashes becomes inconvenient, may be easier with single quotes.
; String containing backslashes
: A string that contains literal backslashes, in particular a regular expression pattern, where doubly escaping certain character sequences is both inconvenient and harder to read, is usually better done with single quotes.
; Argument interpreted differently
: A string argument to the regexp family of functions may be interpreted differently depending on whether it is a double quoted or single quoted string. Certain escape sequences are interpreted only in a single quoted string for Matlab compatibility.
== ending blocks ==
Retrieved from "
Not logged in