help-octave
[Top][All Lists]
Advanced

[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: Ben Abbott
Subject: Re: How can I capture/save my original CSV column headings in a .mat file?
Date: Mon, 20 Apr 2015 08:34:40 -0400

> 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.

Ben

Attachment: csvload.m
Description: Binary data



reply via email to

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