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!