octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #57612] textscan omits final column value for


From: Will Carhart
Subject: [Octave-bug-tracker] [bug #57612] textscan omits final column value for CSV is value is empty
Date: Thu, 16 Jan 2020 13:50:06 -0500 (EST)
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36

URL:
  <https://savannah.gnu.org/bugs/?57612>

                 Summary: textscan omits final column value for CSV is value
is empty
                 Project: GNU Octave
            Submitted by: wcarhart
            Submitted on: Thu 16 Jan 2020 06:50:04 PM UTC
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: Will Carhart
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.2.2
        Operating System: GNU/Linux

    _______________________________________________________

Details:

Running Octave 4.2.2 on Ubuntu 16.04.

textscan will skip the last column value in a CSV file if the column value is
empty. For example, consider this code snippet:

lineFormat = [repmat('%s',1,1), ...
         repmat('%f',1,1), ...
         repmat('%q',1,1), ...
         repmat('%f',1,1), ...
         repmat('%q',1,1)];
C = textscan(fid, lineFormat, 'Delimiter', ',')


With the following CSV data:

102,19700101,,0.485,
111,19700101,,0.48,


I would expect the result of textscan to be:

C =
{
  [1,1] =
  {
    [1,1] = 102
    [2,1] = 111
  }
  [1,2] =
     19700101
     19700101
  [1,3] =
  {
    [1,1] =
    [2,1] =
  }
  [1,4] =
     0.48500
     0.48000
  [1,5] =
  {
    [1,1] =
    [2,1] =
  }
}


However, in reality Octave's textscan produces the following:

C = 
{
  [1,1] = 
  {
    [1,1] = 102
    [2,1] = 19700101
  }
  [1,2] =

     1.9700e+07
            NaN

  [1,3] = 
  {
    [1,1] = 
    [2,1] = 0.48
  }
  [1,4] =

       0.48500
     110.00000

  [1,5] = 
  {
    [1,1] = 111
    [2,1] = 19700101
  }
}


Note that all of the data is shifted by one cell because the last column value
for each line in the CSV is empty. This is not the behavior in MATLAB. In
MATLAB, textscan can parse the above CSV data as expected.

I have tried the options 'MultipleDelimsAsOne'=1 and 'EndOfLine'='\n' and
='\r', but neither changed the behavior.

Is this expected? If so, is there a way to configure Octave's textscan to
perform like MATLAB's?




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57612>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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