How to solve this errror about reading in complex numbers?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
dpb
am 9 Okt. 2022
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 Kommentare
dpb
am 9 Okt. 2022
Bearbeitet: dpb
am 9 Okt. 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!"
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!