worldexplorer95
worldexplorer95

Reputation: 137

Reading portion of CSV with multiple data types

I have a csv file with both numbers and letters that I want to read. The file also has headers(first row) but I can read them separately so that's not a concern. What I can't solve is the fact that the file has multiple data types and that I only want to read a portion(since the file is very large), say the first 5000 rows.

I've tried xlsread with three outputs but I get the following error : "??? Error: Object returned error code: 0x800A03EC". I've also tried textscan but if I understood correctly you've to type the variable types as an input and that's not very practical for me since I have a large amount of columns. I hope this is not a duplicate but I've read other solutions and I could not apply them to my problem.

Is there a way to do this?

Thank you in advance

Upvotes: 1

Views: 625

Answers (1)

zinjaai
zinjaai

Reputation: 2385

To test the problem i created a small test.csv file. It contains the following lines:

header1;header2;header3
a;1;xx
b;2;yy
c;3;zz
d;4;xxx
e;5;yyy

I use the following code to read the data:

range = 'A2:C3'
[num, text, both] = xlsread('test.csv', 1, range)

Output of the both variable, that contains the text and numbers, is as expected:

both = 

    'a'    [1]    'xx'
    'b'    [2]    'yy'

Upvotes: 1

Related Questions