How to solve this errror about reading in complex numbers?
3 次查看(过去 30 天)
显示 更早的评论
filename='plot.csv';
fid=fopen(filename,'r');
data=textscan(fid,'%f %f %f %f %f','Delimiter','Whitespace','HeaderLines',5);
fclose(fid);
data1=cell2mat(data);
real=data1(:,4);
img=data1(:,5);
complex=real+1i*img
after reading the data from .csv format, I want only 4th and 5th column only ... only the last 2 columns.
Then get into a complex number = real+1i*img with format(a+bi), but I am getting an error.
0 个评论
回答(2 个)
dpb
2022-10-9
Previously answered what appears to be virtually identical Q?
The short answer is "read the whole file and save just what need in memory".
2 个评论
dpb
2022-10-9
编辑:dpb
2022-10-9
Well, works just fine for me...
filename=websave('plot.csv','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1150415/plot.csv');
fid=fopen(filename,'r');
data=cell2mat(textscan(fid,'','Delimiter',',','HeaderLines',1));
fclose(fid);
Y=complex(data(:,4),data(:,5))
Don't alias builtin complex function; "there be dragons!"
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!