How to get text file from char
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
TARIK YAMAN
le 28 Oct 2019
Commenté : Shubham Gupta
le 28 Oct 2019
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 commentaires
Réponse acceptée
Shubham Gupta
le 28 Oct 2019
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 commentaires
Shubham Gupta
le 28 Oct 2019
I am glad I could help. If this answer solved your problem, please consider to accept it !
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!