writing complex to a file
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i need to write a complex vector to a file from matlab
i tried
clear;
A=complex(randn(1,5)/sqrt(2),randn(1,5)/sqrt(2));
for k=1:length(A)
tmp=num2str(A(k));
fileID = fopen('tst.txt','wt');
fprintf(fileID,'%s\n',tmp);
fclose(fileID);
end
but it gives only single line in file
0 commentaires
Réponse acceptée
the cyclist
le 10 Mai 2014
Only open and close the file once, not repeatedly in the loop:
clear;
A=complex(randn(1,5)/sqrt(2),randn(1,5)/sqrt(2));
fileID = fopen('tst.txt','wt');
for k=1:length(A)
tmp=num2str(A(k));
fprintf(fileID,'%s\n',tmp);
end
fclose(fileID);
Plus de réponses (1)
dpb
le 10 Mai 2014
>> z
z =
2.7247 + 0.0875i 7.7582 + 0.3089i 3.3141 + 0.2309i 6.0307 + 0.9092i 1.8401 + 0.9369i
>> fmt=['%.2f + %.2fi \n'];
>> fprintf(fmt,[real(z); imag(z)])
2.72 + 0.09i
7.76 + 0.31i
3.31 + 0.23i
6.03 + 0.91i
1.84 + 0.94i
>>
Salt format to suit...above is for human consumption.
0 commentaires
Voir également
Catégories
En savoir plus sur Biological and Health Sciences 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!