Why do I receive an error when I use '\' as the delimiter in the TEXTSCAN command?

4 次查看(过去 30 天)
When I execute the code:
p=cd;
textscan(p,'%s','delimiter','\');
I receive the error:
??? Error using ==> textscan
Delimiter has incorrect \ constant.

采纳的回答

MathWorks Support Team
This change has been incorporated into the documentation in Release 2009b (R2009b). For previous releases, read below for any additional information:
This is an expected behavior in MATLAB. The character '\' is a MATLAB operator and is hence interpreted. In order to pass in the '\' character in its un-interpreted form to the TEXTSCAN command, it needs to be preceeded by the escape character '\'. Therefore, to use '\' as the delimiter in the TEXTSCAN command, execute:
textscan(p,'%s','delimiter','\\');

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by