|
From: | Joao Rodrigues |
Subject: | Re: Import large field-delimited file with strings and numbers |
Date: | Sat, 06 Sep 2014 16:50:23 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
On 09/06/2014 04:40 PM, Andreas Weber wrote:
Am 06.09.2014 16:19, schrieb João Rodrigues:I need to import a large CSV file with multiple columns with mixed string and number entries, such as: field1, field2, field3, field4 A, a, 1, 1.0, B, b, 2, 2.0, C, c, 3, 3.0, and I want to pass this on to something like cell1 ={[1,1] = A; [2,1] = B; [3,1] = C}; cell2 ={[1,1] = a; [2,1] = b; [3,1] = c};Are the first 2 columns only one character long? Then you don't need to use a cell array for this. A simple char matrix would be sufficient.
The strings generally have more than one character. [VAL, COUNT, ERRMSG] = fscanf (FID, TEMPLATE, SIZE)To answer Francesco's comment, fscanf allows for size specification without loop, but I don't know how to write the template indicating that commas (or something else) is a separator. Furthermore, even if the separator is whitespace as output I got a concatenated string instead of multiple fields...
[Prev in Thread] | Current Thread | [Next in Thread] |