help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with reading csv (textscan)


From: PhilipNienhuis
Subject: Re: Problems with reading csv (textscan)
Date: Mon, 19 Aug 2019 12:21:33 -0500 (CDT)

basic_coding wrote
> Thanks for quick answer.
> 
> So here is the simple 3 lines of code I used for the original file:
> file = 'C:\......path_to_file....\messungen1'
> fid = fopen(file, 'r');
> [data] = textscan(fid, '%s %s %f %s %f %s %f %s %f %s %f %s %f %s %f %s
> %f'
> ,'delimiter',';');
> 
> 
> As this didn't work I tried to create a simple csv with comparable
> content:
>     2019-08-16-10:27:28 ;    value 1 ;    5.83 ;    value 2 ;    13 ;
>     2019-08-16-10:27:30 ;    value 1 ;    6.73 ;    value 2 ;    14 ;
> 
> 
> Using the follwoing code lines, I managed to read the data:
> file = 'C:\......path_to_file....\filename.csv'
> fid = fopen(file, 'r');
> [data] = textscan(fid, '%s %s %f %s %f' ,'delimiter',';');

In the io package there's a function called csv2cell that is much faster
than textscan. It'll return a cell array but it's easy to post-process the
numerical part into a numerical array using either:
- cell2mat () or
- parsecell(), also in the io package, which separates the text and
numerical parts into separate arrays w/o much hassle.

You'll need to specify the field delimiter (";") for csv2cell; type "help
csv2cell" and "help parsecell" for the relevant options.

Philip



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]