本文介绍了如何将每个文本拆分成16个字节的块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一个文本拆分为多个块,每个块的大小为16例如:

I need to split a Text in blocs, where the size of every bloc is 16,For example:

文字:

60 3d eb 10 15 ca 71 be 2b 73 ae f0 85 7d 77 81 1f 35 2c 07 3b 61 08 d7 2d 98 10 a3 09 14 df f4 60 3d eb 10 15 ca 71 be 2b 73 ae f0 85 7d 77 81 1f 35 2c 07 3b 61 08 d7 2d 98 10 a3 09 14 df f4

结果:

60 3d eb 10 15 ca 71 be 2b 73 ae f0 85 7d 77 81
1f 35 2c 07 3b 61 08 d7 2d 98 10 a3 09 14 df f4
60 3d eb 10 15 ca 71 be 2b 73 ae f0 85 7d 77 81
1f 35 2c 07 3b 61 08 d7 2d 98 10 a3 09 14 df f4

如果您能帮助我,我将不胜感激.

I would be very grateful if you could help me.

推荐答案

您可以使用fread进行阅读,然后重塑数据.

You can just read this in using fread and then reshape the data.

fid = fopen('filename.txt', 'r');
alldata = fread(fid, '*char');
data = reshape(alldata, 3*16, []).';
fclose(fid)

如果您想要更强大的功能,可以使用textscan.

If you want something a little more robust, you could use textscan.

fid = fopen('filename.txt', 'r');
alldata = textscan(fid, '%s');
data = cell2mat(reshape(alldata{1}, 32, [])).';
fclose(fid)

如果空格很重要,则可以使用strjoin来维护空格

If the spaces are important, you can use strjoin to maintain the spaces

tmp = reshape(alldata{1}, 16, []).';
tmp = arrayfun(@(x)strjoin(tmp(x,:)), 1:size(tmp, 1), 'uniformoutput', false);
data = cat(1, tmp{:})

这篇关于如何将每个文本拆分成16个字节的块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:05