How to solve this errror about reading in complex numbers?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
dpb
el 9 de Oct. de 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 comentarios
dpb
el 9 de Oct. de 2022
Editada: dpb
el 9 de Oct. de 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!"
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!