writedata.m

来自「基于图象的数据隐写和提取matlab代码」· M 代码 · 共 33 行

M
33
字号
function res = writedata(bindat, filename);
%bindat is a stream of binary values
%filename is the file to write to

binmat = [];

% Reconstruct binary matrix
[dnk, sizebindat] = size(bindat);
for i=1:(sizebindat/8)
   bintemp(i,:) = bindat((i-1)*8+1:i*8);
end

binmat=bintemp;

% Get a decimal vector
decvec = transpose(bin2dec(binmat));

% Typecast the decimal vector to a char
% Res is the data that we want to write to the file
res=char(decvec);

% Open the file
% Check to make sure that the file exists
fid = fopen(filename, 'w');
if (fid == -1) 
    error('write_file: cannot open file for writing');
end

% Write data res to file fid
fwrite(fid,res);

% Close the file
fclose(fid);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?