查看单个帖子
旧 2017-04-18, 09:00   #1
hxy110
初级会员
 
注册日期: 2017-02-25
住址: 陕西西安
帖子: 2
声望力: 0
hxy110 正向着好的方向发展
默认 matlab输出的2进制数之间用空格隔开

A = xlsread('Tt3.xlsx');
C = arrayfun(@(x)dec2binPN(x,17),A,'UniformOutput',false);
M = cell2mat(C);
a = strvcat(M);
[x,y] = size(a);
fid = fopen('Tt.txt','wb');
for i = 1:x
fprintf(fid,'%s\n',a(i,);
end
fclose(fid);
程序如上,想让a的每一行都是没17个字符后显示一空格,怎么加循环,让如下加循环
A = xlsread('Tt3.xlsx');
C = arrayfun(@(x)dec2binPN(x,17),A,'UniformOutput',false);
M = cell2mat(C);
a = strvcat(M);
[x,y] = size(a);
fid = fopen('Tt.txt','wb');
for i = 1:x
for j =1:17:136
fprintf(fid,'%s\n',a(i,);
fprintf(fid,'%s ',a(i,j:j+17));
end
end
fclose(fid);
结果只是a的从第二行起前17个字符之后有空格
hxy110 当前离线   回复时引用此帖