help-octave
[Top][All Lists]
Advanced

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

Re: csvread


From: Nicholas Jankowski
Subject: Re: csvread
Date: Wed, 6 Apr 2016 16:51:43 -0400

On Tue, Apr 5, 2016 at 3:55 PM, Nicholas Jankowski <address@hidden> wrote:
> On Tue, Apr 5, 2016 at 3:13 PM, Jonathan Camilleri
> <address@hidden> wrote:
>> It does work but plotting graphs results in nothing that is too meaningful
>> as yet.  I think I would like the addpath command to allow me to have the
>> filename searched for.
>>
>> Environment variables in operating systems work in a similar manner, so I am
>> kind of used to using path as an environment variable that is globally
>> searched for.
>>
>> Not sure if someone can request this on the bug tracker.
>>
>> Jon
>>
>> On 5 April 2016 at 16:18, Mike Miller <address@hidden> wrote:
>>>
>>> On Tue, Apr 05, 2016 at 16:01:34 +0200, Jonathan Camilleri wrote:
>>> > I think I am missing something as I try to read a CSV file to a matrix
>>> > of
>>> > some sort.
>>> >
>>> > >> addpath('C:\Users\slyth_000\Downloads\temp\M.Sc\data-sets\eurofxref')
>>> > >> x = csvread('eurofxref.csv')
>>> > error: dlmread: unable to open file 'eurofxref.csv'
>>>
>>> Yes, you have asked about this before (with pkg, but the same insight
>>> applies to both). The addpath function does not help you in this case.
>>>
>>> Try either cd() to the directory where the file is or use the full file
>>> name. To be clear, either of these should work:
>>>
>>>   cd('C:\Users\slyth_000\Downloads\temp\M.Sc\data-sets\eurofxref')
>>>   x = csvread ('eurofxref.csv')
>>>
>>> or
>>>
>>>   dir = 'C:\Users\slyth_000\Downloads\temp\M.Sc\data-sets\eurofxref';
>>>   x = csvread (fullfile (dir, 'eurofxref.csv'))
>>>
>>> --
>>> mike
>
>
> so I took a minute to look at what Octave does and what we think it
> should do.  Octave pretty clearly states that addpath adds the folder
> to the 'function search path'. so as you'd expect it  executes any
> scripts put in the path. But there seems to be some inconsistency on
> whether other files (such as a csv data file) would be found/used as
> well. i.e., I can fopen a file in a folder that I add with addpath,
> but i cannot open it with csvread (or dlmread, etc)
>
> This does appear to be a Matlab compatibility issue. I just tested
> with Matlab 2015b, and using addpath, I can run both scripts as well
> as open data files in locations added with addpath.  I can open the
> csv file with fopen and with csvread.
>
> Since it does appear as a compatibility issue, I'll open a bug report
> and let those more knowledgeable of the inner workings debate what it
> should do and how it might be fixed.
>
> That said, I wouldn't expect this to hit the release version any time
> soon. For now you should probably use one of Mike's suggestions to
> access data files.
> Nick J.

Jon, since you likely don't see the conversations on the bug report
tracker, thought I'd share this workaround from Mike that would work
for your code:

Follow-up Comment #3, bug #47628 (project octave):

A Matlab compatible workaround is to use the which function when you want to
open a data file for reading that is intended to be found on the function load
path:


>> x = csvread(which('mytestdata.csv'))
x =

   1   2   3   4
   4   3   2   1


This should make code written for Octave do what you seem to be
wanting, and it will still work it Matlab if that is a concern.

Nick J.



reply via email to

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