help-octave
[Top][All Lists]
Advanced

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

Re: Reading mixed csv files with csvread or dlm read


From: Philip Nienhuis
Subject: Re: Reading mixed csv files with csvread or dlm read
Date: Sat, 25 Oct 2014 07:09:42 -0700 (PDT)

Vincent Gizzo wrote
> Hello,
> 
> I am trying to read a csv file with csvread or dlmread. If the csv files
> have only 3 columns with numerical data and a header row, everything is
> fine. If I use a different type that has numerical data in 3 columns and
> text in the other columns, all elements in the matrix are 0.
> 
> How can I input the numerical data only without opening the csv file and
> deleting the other columns.
> 
> Here is the code I am using:
> 
> 
> function [data,predata,postdata] = GParse (ftarget)
> 
> #declarations
> datasheet=[];
> precontours=[];
> pstcontours=[];
> 
> 
> #Load pre and post files
> prefiles=glob ("*PRE*");
> pstfiles=glob ("*POST*");
> fname=char(prefiles(1));
> 
> #Make datasheet and enter coordinates for first 2 columns
> coor=csvread(fname,1,0);coor=coor(:,1:2);
> datasheet=[datasheet,coor];
> 
> #create data files for contourbatch function
> precontours=[precontours,coor];
> pstcontours=[pstcontours,coor];
> 
> 
> for i=1:size(prefiles,1)
>   fname=char(prefiles(i));
>   zpre=csvread(fname,"C2:C70");
>   fname=char(pstfiles(i));
>   zpst=csvread(fname,"C2:C70");
>   etarget=zpre-ftarget;
>   eactual=zpre-zpst;
>   error=eactual-etarget;
>   datasheet=[datasheet,zpre,zpst,target,eactual,eerror];
>   precontours=[precontours,zpre];
>   pstcontours=[pstcontours,zpst];
> endfor
> 
> stats=[mean(datasheet);min(datasheet);max(datasheet);range(datasheet);std(datasheet)];
> datasheet=[datasheet;stats];
> data=datasheet;
> endfuncion

Have you tried csv2cell() in the OF io package? That should be able to read
mixed data from .csv.

As of io-2.2.4 csv2cell has a headerlines parameter.
csv2cell doesn't have a cell range parameter.

Philip



--
View this message in context: 
http://octave.1599824.n4.nabble.com/Reading-mixed-csv-files-with-csvread-or-dlm-read-tp4667086p4667109.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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