How to get text file from char
3 次查看(过去 30 天)
显示 更早的评论
hi, i have a problem.ı want get text form char matrix, fprintf doesnt work, how to get text file form matrix "T".
clc;
clear;
tic
b = sprintf('0123456789');
d = 0;
T = char;
for iiiii = 1:10
for iiiiii = 1:10
for iiiiiii = 1:10
for iiiiiiii = 1:10
for iiiiiiiii = 1:10
for iiiiiiiiii = 1:10
for iiiiiiiiiii = 1:10
d = d + 1;
T(d,1:4) = '0534';
T(d,5) = b(iiiii);
T(d,6) = b(iiiiii);
T(d,7) = b(iiiiiii);
T(d,8) = b(iiiiiiii);
T(d,9) = b(iiiiiiiii);
T(d,10) = b(iiiiiiiiii);
T(d,11) = b(iiiiiiiiiii);
fprintf('%s\n',T(d,:));
end
end
end
end
end
end
end
toc
0 个评论
采纳的回答
Shubham Gupta
2019-10-28
Try :
clc;
clear;
tic
fid = fopen('myFile.txt','w'); % open text file
b = sprintf('0123456789');
d = 0;
T = char;
for iiiii = 1:10
for iiiiii = 1:10
for iiiiiii = 1:10
for iiiiiiii = 1:10
for iiiiiiiii = 1:10
for iiiiiiiiii = 1:10
for iiiiiiiiiii = 1:10
d = d + 1;
T(d,1:4) = '0534';
T(d,5) = b(iiiii);
T(d,6) = b(iiiiii);
T(d,7) = b(iiiiiii);
T(d,8) = b(iiiiiiii);
T(d,9) = b(iiiiiiiii);
T(d,10) = b(iiiiiiiiii);
T(d,11) = b(iiiiiiiiiii);
fprintf(fid,'%s\n',[T(d,:),char([13,10])]); % print T in your text file indicated by fid
end
end
end
end
end
end
end
fclose all % close text files
toc
You will get a text file named 'myFile.txt' in your working directory. Let me know if you have doubts !
2 个评论
Shubham Gupta
2019-10-28
I am glad I could help. If this answer solved your problem, please consider to accept it !
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!