If you want to define a string that has a single quote inside it, you might run into trouble. Let’s say I define
S =' This sentence has a single quotation mark ', what's wrong with '%MATLAB'Copy the code
Duplicate the first and second single quotes of the code to pair. You can’t get our results.
Here’s what you do:
S =' this sentence has a single quotation mark ', how about '%matlab passCopy the code
This is also something to consider when using commands like disp,sprintf, fprintf, and eval. Or you’ll be struggling like I was…
Disp ('') % Error disp('''') % positive solutionCopy the code
Attach all escape characters in MATLAB.
‘ ‘ | Single quotation mark |
---|---|
% % | Percent character |
\ \ | Backslash |
\a | Alarm |
\b | Backspace |
\f | Form feed |
\n | New line |
\r | Carriage return |
\t | Horizontal tab |
\v | Vertical tab |
\xN | Hexadecimal number, N |
\N |