2

是否可以更改默认的 '\n' Matlab 行终止符?我可以使用 ',' 代替 '\n' 吗?因为将读取它的串行端口被编程为在读取“,”时终止。这可能吗?任何答案都非常感谢!提前致谢!

4

2 回答 2

0

使用例如:

ser = serial('COM1');   % establish connection between Matlab and COM1

set(ser, 'Terminator', 'CR'); % set communication string to end on ASCII 13

并替换'CR'','

http://www.swarthmore.edu/NatSci/ceverba1/Class/e5/E5MatlabExamples.html http://www.mathworks.co.uk/help/matlab/matlab_external/terminator.html

于 2014-03-06T13:27:57.813 回答
0

matlab 中的简单字符串不会以 \n 或 \0 结尾,因为它是一个简单的字符数组,如下所示:

>> a = string('Hello World')
Warning: string is obsolete and will be discontinued.
         Use char instead. 

a =

Hello World

>> double(a)

ans =

    72   101   108   108   111    32    87   111   114   108   100

在末尾添加 \0 只需使用:

>> a(end+1)=0;
>> a

a =

Hello World 

>> double(a) %the zero is there, but not printable as seen here

ans =

    72   101   108   108   111    32    87   111   114   108   100     0
于 2014-03-06T13:30:23.710 回答