cannot save quadrature data

조회 수: 1 (최근 30일)
NoYeah
NoYeah 2020년 8월 7일
답변: Walter Roberson 2020년 8월 7일
I have this kind of data
{1 + 2i
3 + 4i
2 + 7i
....}
I used fprintf to save the above
file_name = fopen('data.txt','w');
fprintf(file_name, '%s\r\n', data);
fclose(file_name)
I got data.txt and theronly exist the real value
like
1
3
2
....
not the
1 + 2i
3 + 4i
2 + 7i
...
How to save this data type properly?

채택된 답변

Walter Roberson
Walter Roberson 2020년 8월 7일
file_name ='data.txt';
fid = fopen(file_name, 'w');
fprintf(fid, '%.17e%+.17ei\r\n', [real(data.'); imag(data.')]);
fclose(fid)
I deliberately did not put a space between the real and imaginary parts: some parsing software can only detect the imaginary part as being part of the same number if there is no space. You can put a space before %+ if you want.
If you need a space after the sign for the complex part, then that would need more work.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by