matlab讀寫bin文件默認使用uint8格式進行讀取,這與實際情況有區別,比如我要寫入一個short類型的數據,就很難實現,具體代碼參考如下:
A = fread(fileID,sizeA,precision)
用precision來控制讀入和寫出的精度,類型涵蓋了所有格式基本上, short,unsigned short等。。。。
clc;clear;close all
%% 寫數據
fileID1=fopen('01.bin','w');
A = 0:1:15;
fwrite(fileID1,A', 'uint16');
fclose(fileID1);
%% 讀數據
fileID2=fopen('01.bin','r');
B=fread(fileID2, 'int16');
fclose(fileID2);
%%