[Top][All Lists]

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

Re: How can I capture/save my original CSV column headings in a .mat fil

From: George Matysiak
Subject: Re: How can I capture/save my original CSV column headings in a .mat file?
Date: Mon, 20 Apr 2015 15:40:37 +0200

Many thanks for that, appreciated.

I'm new to octave and just getting my head around coding. I'm not clear where I should place the line:
s = csvload (your_csv_file, “returnstruct”, true, “headerlines”, 1);

This is what I had for the function:
function [out, header] = csvload ('An2.csv', varargin), where 'An2.csv' was my comma delimited file.

Lots of error messages ensued.



Contact number +48 781 415 432

On 20 April 2015 at 14:34, Ben Abbott <address@hidden> wrote:
> On Apr 19, 2015, at 6:16 PM, Farmer <address@hidden> wrote:
> I've looked around on the site but cannot find what I'm looking for.
> CSV data is downloaded to Octave without the column/heading descriptors i.e.
> a pure data matrix results. What would be the most efficient approach in
> reading the original headings/column names in the csv file and name my
> imported data vectors/columns, subsequently saving the file as a .mat file?
> For example, would it be possible to pre-prepare a list of names and
> reference them, perhaps by way of a loop?
> Be very grateful for suggestions, as I'm sure I'm not the first to encounter
> this. Many thanks.
> Farmer

I’ve written a script that does something very similar (csvload.m). It is attached.

You can use the script to load a csv-file into a structure whose field-names are taken from the column headers, and then save the data using the -struct option.

        s = csvload (your_csv_file, “returnstruct”, true, “headerlines”, 1);
        save your_mat_file.mat -struct s

The script does more than you require. So you may wish to modify it to suit your needs.


reply via email to

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