How to get text file from char
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
TARIK YAMAN
el 28 de Oct. de 2019
Comentada: Shubham Gupta
el 28 de Oct. de 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 comentarios
Respuesta aceptada
Shubham Gupta
el 28 de Oct. de 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 comentarios
Shubham Gupta
el 28 de Oct. de 2019
I am glad I could help. If this answer solved your problem, please consider to accept it !
Más respuestas (0)
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!