From: Judy on
Is there any way to read a .csv file with the contents

- 1, 2

... that is a negative sign followed by some spaces and then a number?

I've tried
fid=fopen(dir)
data = textscan(fid,'%d','Delimiter',',','whitespace','')
fclose(fid)

They give me an empty array:
fid =

3


data =

{[]}


ans =

0

Thanks~
From: us on
On Aug 4, 11:51 pm, "Judy " <sauwen...(a)gmail.com> wrote:
> Is there any way to read a .csv file with the contents
>
> -     1, 2
>
> .. that is a negative sign followed by some spaces and then a number?
>
> I've tried
> fid=fopen(dir)
> data = textscan(fid,'%d','Delimiter',',','whitespace','')
> fclose(fid)
>
> They give me an empty array:

a hint:

data=textscan(fid,'%d','delimiter',',','whitespace','-');

us
From: Judy on
us <us(a)neurol.unizh.ch> wrote in message <240b660f-de2e-4a79-89dc-5da0cca75408(a)o19g2000yqb.googlegroups.com>...
> On Aug 4, 11:51 pm, "Judy " <sauwen...(a)gmail.com> wrote:
> > Is there any way to read a .csv file with the contents
> >
> > -     1, 2
> >
> > .. that is a negative sign followed by some spaces and then a number?
> >
> > I've tried
> > fid=fopen(dir)
> > data = textscan(fid,'%d','Delimiter',',','whitespace','')
> > fclose(fid)
> >
> > They give me an empty array:
>
> a hint:
>
> data=textscan(fid,'%d','delimiter',',','whitespace','-');
>
> us

Hi us,

I tried your hint. Does that insert a negative sign for every whitespace? It made the code happier, but it threw away the negative sign now so when I did
fid=fopen(dir)
data=textscan(fid,'%d','delimiter',',','whitespace','-')
fclose(fid)
data=cell2mat(data)

data =

1
2

Thanks
From: us on
"Judy "
> I tried your hint. Does that insert a negative sign for every whitespace? It made the code happier, but it threw away the negative sign now so when I did
> fid=fopen(dir)
> data=textscan(fid,'%d','delimiter',',','whitespace','-')
> fclose(fid)
> data=cell2mat(data)

ok... the assumption was that the ...negative sign... was more of a dash/flag and NOT part of the number...
in this case, things are less trivial...
you should better explain your input, eg,
- is there always a sign, including a +
- are numbers always integers
- is there always a comma between numbers
- are there always two numbers

a few(!) more typical lines of your input and what you expect the output to look like would be helpful...

us
From: Walter Roberson on
us wrote:
> "Judy "
>> I tried your hint. Does that insert a negative sign for every
>> whitespace? It made the code happier, but it threw away the negative
>> sign now so when I did
>> fid=fopen(dir)
>> data=textscan(fid,'%d','delimiter',',','whitespace','-')
>> fclose(fid)
>> data=cell2mat(data)
>
> ok... the assumption was that the ...negative sign... was more of a
> dash/flag and NOT part of the number...
> in this case, things are less trivial...
> you should better explain your input, eg,
> - is there always a sign, including a +
> - are numbers always integers
> - is there always a comma between numbers
> - are there always two numbers

To which I would add the question of whether there is ever a negative sign for
the second element; if there is one, does it follow immediately after the
comma or is there a space after the comma and before the negative sign?

textscan(fid, '%c%d%d', 'delimiter', ','. 'Collect', 1)

handles the case of there never being a negative sign for the second number.
The returned cell array would have a character component that was '-' for the
negative sign and space if there is no leading negative sign. Take the N x 2
numeric array that is output, and negate the elements of the first column that
correspond to the rows for which the character component is '-' .