writing complex to a file

29 visualizaciones (últimos 30 días)
yasser
yasser el 10 de Mayo de 2014
Comentada: yasser el 10 de Mayo de 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

Respuesta aceptada

the cyclist
the cyclist el 10 de Mayo de 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);

Más respuestas (1)

dpb
dpb el 10 de Mayo de 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.

Categorías

Más información sobre Biological and Health Sciences en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by