How to read complex number from a *.csv file?

Hi,
I have to import a data set from a csv file but I cannot find any way to import the complex number from the file to Matlab to do the data processing. I try to search on the internet but no solutions are helpful. I tried importdata, csvread, textread,... but they didn't work. Can anyone show me how to solve this problem? I attached part of my csv file below. I really need help. Thanks

답변 (2개)

sixwwwwww
sixwwwwww 2013년 12월 5일

0 개 추천

you can do it as follows:
[num, str, raw] = xlsread('filename.csv');
a = str2num(cell2mat(raw));

댓글 수: 5

Ngoc
Ngoc 2013년 12월 5일
Thank you for answering me. I do what you recommended but matlab said: "Error using cell2mat (line 46) All contents of the input cell array must be of the same data type." Attached below is how the raw data looks, and I don't know why the input cells are not of the same data type.
Ngoc
Ngoc 2013년 12월 5일
Ah, maybe 0 is treated as a number, not a string. But the problem is still not solved.
sixwwwwww
sixwwwwww 2013년 12월 5일
can you upload your csv file for better look into your data?
Ngoc
Ngoc 2013년 12월 5일
Here it is. This is only a small part that I cut from the file, which is too large to upload here.
Use the following code on your data. It will work fine. I checked it for your sample data:
[num, str, raw] = xlsread('filename.csv');
rawval = double(cellfun(@(x) ~isnumeric(x), raw));
a = zeros(size(raw));
b = a;
a(rawval == 0) = cell2mat(raw(rawval == 0));
b(rawval == 1) = str2double(raw(rawval == 1));
Matrix = a + b;
I hope it helps. Good luck!

댓글을 달려면 로그인하십시오.

G A
G A 2013년 12월 5일

0 개 추천

https://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/239213

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

태그

질문:

2013년 12월 5일

댓글:

2013년 12월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by