I searched many posts on the Internet, but they were all just a few words, afraid that others would learn it. Either they ignored me, or they thought they were superior to me even if they did. It's just a few lines of broken program, I wrote it, take it. A reminder to students who use it, please modify the Q value according to the data you want to process. Q=14;%The data is between -1.x and +1.x, so Q14 is taken x=0; fid=fopen('resdata_a.dat','w');%Open file fprintf(fid,'1651 1 0 1 0\n');%Output file header data_len=length(resdata_a);%Assume that the data to be processed is stored in resdata_a for i=1:data_len if resdata_a(i)>=0 x=round(resdata_a(i)*2^Q);%Round after converting to Q format fprintf(fid,'0x%x\n',x);% output in hexadecimal else x=2^16-round(abs(resdata_a(i))*2^Q);%Find the complement of negative numbers fprintf(fid,'0x%x\n',x);% output end end fclose(fid);%After completion, there will be no information prompt in the Matlab command window