简体   繁体   English

如何使用MATLAB在文件中读取复数

[英]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: 我需要使用MATLAB读取txt文件的值,该文件位于:

-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 但是我对这个值6.12323e-17有一些麻烦,在我阅读它的matlab中,谷值是0.0000

here is the MATLAB code: 这是MATLAB代码:

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 ? 如何处理0.0000

Thanks in advance 提前致谢

You are using %f which is fixed point. 您正在使用%f这是固定点。 Use %e for exponential notation. 使用%e表示指数。 Check out mathwork's web site: http://www.mathworks.com/help/matlab/matlab_prog/formatting-strings.html?refresh=true 请访问mathwork网站: 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. 它不是0,在matlab打印矩阵时,它对所有元素使用相同的符号,因此打印值被截断,但存储的值不是。

Try printing just the imaginary part of the second number. 尝试仅打印第二个数字的虚部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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