默认'\ n'可以更改Matlab行终止符吗?我可以使用','而不是'\ n'吗?因为读取它的串口被编程为在','读取时终止。是否可能? 任何答案都非常感谢!提前谢谢!
答案 0 :(得分: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
答案 1 :(得分: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