我在Matlab中有一个与两个Android智能手机通信的脚本。以下是代码的相关部分:
% wait for a client
t = tcpip('0.0.0.0',8080,'NetworkRole','server');
%set read buffer
set(t,'InputBufferSize',6000);
set(t,'Timeout',3);
% open the socket
fopen(t);
%read the bytes
file=fread(t,6000,'uint8');
%do something with the file
[a,~]=find(file);
file((a(end))+1:end)=[]; %here is the problem
%close the socket
fclose(t);
有时,当客户端连接时,脚本会返回错误:
Subscripts indices must either be real positive integer or logicals.
我不确定这是否是网络错误,或者我编写代码的方式是否有错误?