help-octave
[Top][All Lists]
Advanced

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

Re: Importing data that contains a mix of numerical and string data


From: Philip Nienhuis
Subject: Re: Importing data that contains a mix of numerical and string data
Date: Wed, 14 Nov 2018 18:39:59 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0 SeaMonkey/2.48

Owen,

First of all: please don't top post, answer BELOW the email. That's the netiquette here.
See bottom for the rest of my reply

Owen Cail wrote:
Below is an example of how I can use Matlab to read the type of file I
gave an example of earlier.  Sorry if this doesn't display very well.
If there are some tags that I could put around my text to make it appear
nice and neat on this platform then let me know.

pathToFile = 'testData.csv';
fprintf('Opening file: "%s"\n', pathToFile);
raw = importdata(pathToFile, ',');
if isequal(raw, 0)
    fprintf('Could not import raw data.\n\n');
else
    fprintf('Now parsing data...\n');
    dimensionsText = size(raw.textdata);
    dimensionsData = size(raw.data);
    if dimensionsText(1) == dimensionsData(1)
        % if raw.textdata is the same length as data, then the
        % file was corrupted and doesn't have column titles or
        % decimal places.
        warning(['Selected data log was recovered from a ' ...
                'corrupted log.  Be wary of unexpected results.'])
        logDate = raw.textdata(:, 1);
        timeOfDay = raw.textdata(:, 2);
        value1 = raw.data(:, 1) ./ 1000;
        value2 = raw.data(:, 2) ./ 1000;
    else
        logDate = raw.textdata(2:end, 1);
        timeOfDay = raw.textdata(2:end, 2);
        value1 = raw.data(:, 1);
        value2 = raw.data(:, 2);
    end
end



On Tue, 13 Nov 2018 at 13:10, PhilipNienhuis <address@hidden
<mailto:address@hidden>> wrote:

    Owen Cail wrote
    > I'll start by saying I'm in the process of moving from Matlab to
    Octave.
    >
    > I am trying to import data from a text file, such as the example
    below:
    >
    > date,             time,               value1,  value2
    > 2018-11-12, 15:44:21.123, 13,        205
    > 2018-11-12, 15:44:22.123, 17,        201
    >
    > The result of is a struct with two fields: one called data, and
    one called
    > textdata:
    >
    >   data =
    >
    >         13   205
    >         17   201
    >
    >      textdata =
    >     {
    >       [1,1] = date,       time,         value1, value2
    >       [2,1] = 2018-11-12
    >       [3,1] =  15:44:21.123
    >       [4,1] = 2018-11-12
    >       [5,1] =  15:44:22.123
    >     }
    >
    > The data part is exactly what I would expect, but the textdata
    result is
    > in
    > a form that is not very useful.  In Matlab, I was able to have a
    column
    > full of dates and a column full of times.  The header being all in one
    > cell
    > is weird but is fine.  My issue is that both columns of data are
    combined
    > in to one column.
    >
    > Is this intended behavior and I should just deal with it?  Or can
    I submit
    > a bug report with these details?

    How would you read this with matlab? Any code example?

    P

Right, so this is a Matlab compatibility issue.
Would you please file a bug report, include the code snippet and attach the test file there.

Thanks,

Philip



reply via email to

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