How to use “csvread” when the contents in the file have different formats?

后端 未结 2 1729
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 21:44

I have a .csv file and the format is shown below:

mapping.csv

5188.40811,TMobileML
5131.40903,TMobileGregsapt
5119.40791,TMobileJonsapartment
5123.40         


        
相关标签:
2条回答
  • 2020-12-11 22:16

    Another answer that will work if you have mixed text/numeric csv but you either don't know what the format is, or it's heterogeneous, use the 'csv2cell' function from: http://www.mathworks.com/matlabcentral/fileexchange/20836-csv2cell

    c = csv2cell( 'yourFile.csv', 'fromfile'); 
    

    c(1, :) will give your headers and c(2:end, k) will give you each of the columns (sans the header), for k = 1:size(c, 2)

    0 讨论(0)
  • 2020-12-11 22:31

    Both csvread and dlmread only work for numeric data. Something like this should work for you

    out=textread('tmp.csv', '%s', 'whitespace',',');
    nums =  out(1:2:end);
    strs =  out(2:2:end);
    % find index of 'TMobileGregsapt'
    ind = find(strcmp('TMobileGregsapt',strs));
    nums(ind)
    
    0 讨论(0)
提交回复
热议问题