Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Reading a csv file with a mix of numbers and words
Replies: 1   Last Post: Apr 23, 2013 12:26 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,892
Registered: 12/7/04
Re: Reading a csv file with a mix of numbers and words
Posted: Apr 23, 2013 12:26 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Tuesday, April 23, 2013 2:44:09 PM UTC+12, Pawan Dubey wrote:
> hello guys,
>
> been looking to read a text file with comma seperated values
>
>
>
> Looks something like this
>
>
>
> Experiment Title,Solar Cell Testing,,,,,,,
>
> ,,,,,,,,
>
> ,,,,,,,,
>
> ,,,,,,,,
>
> ,,,,,,,,
>
> ,,,,,,,,
>
> ,,,,,,,,
>
> ,,,,,,,,
>
> ,,,,,,,,
>
> ,,,,,,,,
>
> Voltage,Readings Current Density,Readings Power Density,,,,,,
>
> 1.50E+00,-1.11E-01,-1.67E-01,,,,,,
>
> 1.49E+00,-1.12E-01,-1.67E-01,,,,,,
>
> 1.48E+00,-1.11E-01,-1.64E-01,,,,,,
>
> 1.46E+00,-1.10E-01,-1.61E-01,,,,,,
>
> 1.45E+00,-1.08E-01,-1.57E-01,,,,,,
>
>
>
> It goes on and on and I do not want to count the number of columns because that may easily run up different for different files and is usually in thousands
>
> How do I read this file and get the numeric data in a separate matrix of a countless number of rows wich will be different for different files I will be working with and 3 columns containing only the numeric data.
>
> Really looking for some help here as i am not much sure about how much i can play with csvread, dlmread etc
>
> Thanks


You need to use textscan.
It's not clear from your post if there is one header in each file followed by an unknown number of lines of data, or there are an unknown number of header lines followed by data.
Assuming the former:
fid=fopen('YourFilename','rt');
c=textscan(fid,'%f%f%f',...
'headerlines',1,...
'delimiter',',');



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.