字符组并形成在Matlab矩阵 [英] Group characters and form a matrix in Matlab
本文介绍了字符组并形成在Matlab矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有26个字符A到Z,I组4个字符在一起,并以这是这样一个空间下面的4个字符分隔:
I have 26 characters A to Z, I group 4 characters together and separate the following 4 characters by a space which is like this:
abcd efgh ijkl mnop qrst uvwx yz
我的Matlab的编码如下:
My Matlab coding is as follows:
海峡='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
FSTR = [repmat('%C',1,4)''];
A = fprintf中(FSTR,STR);
问题:我想使它成为一个新的生产线时,有一排是这样8个字:
Problem: I wish to make it a new line when there are 8 characters in a row which is like this:
abcd efgh
ijkl mnop
qrst uvwx
yz
任何想法做到这一点?请帮忙。
Any ideas to do this? Please help.
感谢您。
推荐答案
code(带的 vec2mat
) -
%// Input
input_str = 'abcdefghijklmnopqrstuvwxyz' %// Input
%// Parameters
group_numel = 4;
num_groups_per_row = 2;
str1 = vec2mat(input_str,group_numel)
str2 = [str1,repmat(' ',size(str1,1),1)]
output_str = vec2mat(str2,(group_numel+1)*num_groups_per_row)
code运行 -
>> input_str
input_str =
abcdefghijklmnopqrstuvwxyz
>> output_str
output_str =
abcd efgh
ijkl mnop
qrst uvwx
yz
这篇关于字符组并形成在Matlab矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文