How to solve this errror about reading in complex numbers?
Show older comments
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.
Answers (2)
dpb
on 9 Oct 2022
0 votes
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 Comments
riki singh
on 9 Oct 2022
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!"
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!