Discussion:
Importing data that contains a mix of numerical and string data
Owen Cail
2018-11-12 22:37:36 UTC
Permalink
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?
PhilipNienhuis
2018-11-13 19:09:17 UTC
Permalink
Post by Owen Cail
I'll start by saying I'm in the process of moving from Matlab to Octave.
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
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



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Owen Cail
2018-11-14 04:35:56 UTC
Permalink
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
Post by Owen Cail
Post by Owen Cail
I'll start by saying I'm in the process of moving from Matlab to Octave.
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
Post by Owen Cail
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
Post by Owen Cail
a bug report with these details?
How would you read this with matlab? Any code example?
P
--
http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Philip Nienhuis
2018-11-14 17:39:59 UTC
Permalink
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
Post by Owen Cail
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
Post by Owen Cail
I'll start by saying I'm in the process of moving from Matlab to
Octave.
Post by Owen Cail
I am trying to import data from a text file, such as the example
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
Post by Owen Cail
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
Post by Owen Cail
in
a form that is not very useful. In Matlab, I was able to have a
column
Post by Owen Cail
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
Post by Owen Cail
in to one column.
Is this intended behavior and I should just deal with it? Or can
I submit
Post by Owen Cail
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

Loading...