writing complex to a file

29 vues (au cours des 30 derniers jours)
yasser
yasser le 10 Mai 2014
Commenté : yasser le 10 Mai 2014
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

Réponse acceptée

the cyclist
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);
  1 commentaire
yasser
yasser le 10 Mai 2014
thanks alot

Connectez-vous pour commenter.

Plus de réponses (1)

dpb
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.

Catégories

En savoir plus sur Biological and Health Sciences dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by