How to read complex number from a *.csv file?
25 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
sixwwwwww
2013-12-5
you can do it as follows:
[num, str, raw] = xlsread('filename.csv');
a = str2num(cell2mat(raw));
5 个评论
sixwwwwww
2013-12-5
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!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!