How to get text file from char

3 vues (au cours des 30 derniers jours)
TARIK YAMAN
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

Réponse acceptée

Shubham Gupta
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
TARIK YAMAN
TARIK YAMAN le 28 Oct 2019
I fixed, thanks to you.
I wrote fprintf(fid,'%s\n',[T(d,:),char()]) instead of fprintf(fid,'%s\n',[T(d,:),char([13,10])]).
clc;
clear;
tic
b = sprintf('0123456789');
d = 0;
T = char;
fid = fopen('myFile.txt','w');
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()]);
end
end
end
end
end
end
end
toc
fclose = fid;
Shubham Gupta
Shubham Gupta le 28 Oct 2019
I am glad I could help. If this answer solved your problem, please consider to accept it !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by