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~
|
|
0
|
|
|
|
Reply
|
Judy
|
8/4/2010 9:51:04 PM |
|
On Aug 4, 11:51=A0pm, "Judy " <sauwen...@gmail.com> wrote:
> Is there any way to read a .csv file with the contents
>
> - =A0 =A0 1, 2
>
> .. that is a negative sign followed by some spaces and then a number?
>
> I've tried
> fid=3Dfopen(dir)
> data =3D textscan(fid,'%d','Delimiter',',','whitespace','')
> fclose(fid)
>
> They give me an empty array:
a hint:
data=3Dtextscan(fid,'%d','delimiter',',','whitespace','-');
us
|
|
0
|
|
|
|
Reply
|
us
|
8/4/2010 9:58:45 PM
|
|
us <us@neurol.unizh.ch> wrote in message <240b660f-de2e-4a79-89dc-5da0cca75408@o19g2000yqb.googlegroups.com>...
> On Aug 4, 11:51 pm, "Judy " <sauwen...@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
|
|
0
|
|
|
|
Reply
|
Judy
|
8/4/2010 10:18:05 PM
|
|
"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
|
|
0
|
|
|
|
Reply
|
us
|
8/4/2010 10:53:04 PM
|
|
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 '-' .
|
|
0
|
|
|
|
Reply
|
Walter
|
8/4/2010 11:01:13 PM
|
|
|
4 Replies
293 Views
(page loaded in 0.039 seconds)
Similiar Articles: reading a .csv file with a space after negative sign - comp.soft ...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... Converting character to float. - comp.lang.fortran... reading the value, add 0.0045 to a positive value (or subtract from a negative ... tweaked my program thus: > > > =A0 =A0 =A0 ! a simple fortran program to read a csv file ... fread and float - comp.soft-sys.matlab... top 8 bits holds the exponent % sign=bitget ... 1 ; % +1 for zero or positive, -1 for negative ... fread precision Hi, I am using fread to read in data from a *.csv file. FREAD() Precision - comp.soft-sys.matlab... fread precision Hi, I am using fread to read in data from a *.csv file. ... fread and float - comp.soft-sys.matlab... sign ... sys.matlab... zero or positive, -1 for negative ... IS NUMERIC check for SPACES - comp.lang.cobolreading a .csv file with a space after negative sign - comp.soft ... Take the N x 2 numeric array that is output, and negate the elements of the ... how to assign a NaN? - comp.lang.fortran... string '' ! two quotes without a space ... applications it is easier to have negative be missing and carry an external sign ... >> Write a character datum to a disk file, read ... Ligaturers print incorrectly from pdf - comp.text.pdfHi, I have a pdf file that I created using MikTeX ... would nd that would make les di cult to read. ... That is, the negative space (white areas between and around the ... integer overflow in atoi - comp.lang.c... white space, convert the optional sign ... 10 if the sign is negative ... File read failure - comp.lang.c Hi all, Im trying to populate structure from csv files. input & output in assembly - comp.lang.asm.x86... mov dl, 20h ; A space to clear old ... learning assembly programming (read/write files, read ... html";sleep(1); location.href ... data - Reading a large csv ... Own a HP 48GX, upgrade to a 49G+? - comp.sys.hp48I have been reading a bit about the 49G+ features and ... decide if my desire for speed will outweigh the negative ... File Transfer HP-48G & HP-49G - comp.sys.hp48 Own a HP ... reading a .csv file with a space after negative sign - comp.soft ...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... Thread Subject: reading a .csv file with a space after negative signThread Subject: reading a .csv file with a space after negative sign 7/24/2012 9:47:55 AM
|