如何用matlab读取.txt文件

clear all;
close all;
clc
fid=fopen(['dpram.txt'],'r');
%方法1:
[raw_str,COUNT]=fscanf(fid,'%s'); %具体什么格式视情况而定,也可以%d
%方法2:
%raw_str = textscan(fid,'%s');
%[COUNT,a] = size(raw_str{1,1});
%raw_str_cell = raw_str{1,1}(1:COUNT,:);
%raw_str_op= hex2dec(cell2mat(raw_str_cell));
%raw_str_op = dec2bin(raw_str_op);

fclose(fid);

for i=1:762
    raw_str_op(i,1:8) = raw_str((i-1)*8+1:i*8);
end
raw_str_op = hex2dec(raw_str_op);
raw_str_op = dec2bin(raw_str_op);

fid_s = fopen('LUT.mif', 'w');
for i=1:length(raw_str_op)
    fprintf(fid_s, '%s', raw_str_op(i,:));
    fprintf(fid_s, '%s\n', '');
end
fclose(fid_s);
disp('===================转换完成=========================');

猜你喜欢

转载自blog.csdn.net/qq_43445577/article/details/109676032
今日推荐