简体   繁体   中英

How can I read a complex number with MATLAB in a file

I need read values of a txt file with MATLAB, the file is here:

-0.933475 0.358642
-1 6.12323e-17

but I have some troubles with this value 6.12323e-17 , in matlab when I read it, the vale is 0.0000

here is the MATLAB code:

close all; clear;
arquivo = fopen('fftOut.txt');
formatSpec = '%f %f';
sizeA = [2 inf];
X = fscanf(arquivo,formatSpec, sizeA);
X'
fclose(arquivo);

and the output is

   -0.9335    0.3586
   -1.0000    0.0000

How can I handle it 0.0000 ?

Thanks in advance

You are using %f which is fixed point. Use %e for exponential notation. Check out mathwork's web site: http://www.mathworks.com/help/matlab/matlab_prog/formatting-strings.html?refresh=true

It's not 0, when matlab prints a matrix, it uses the same notation for all elements, so the printed value is truncated but the stored one isn't.

Try printing just the imaginary part of the second number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM