[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: textread proeblem
From: |
Philip Nienhuis |
Subject: |
Re: textread proeblem |
Date: |
Wed, 20 Aug 2014 02:53:55 -0700 (PDT) |
Nidjara wrote
> Hi,
> I'm reading graphwiz .dot file with octave. This is the sample of the
> file:
> digraph G {
> 1->0 [weight="131932"];
> 2->1 [weight="259178"];
> 3->2 [weight="732180"];
> 4->3 [weight="137337"];
> 5->1 [weight="521430"];
> 6->5 [weight="87498"];
> 7->3 [weight="912756"];
> 8->1 [weight="191335"];
> 9->1 [weight="329365"];
> ..
>
> I wish to store the first number of every line in vector L1, the second
> number in L2 and the third in L3, ignoring the text. For example, I would
> like to have 1 in L1(1), 0 in L2(1) and 131932 in L3(1), after loading the
> data. In matlab this code does the trick:
>
> [L1 L2 L3]= textread('Graph.dot','%u %*2s %u [weight="%d"] %*s',
> 'delimiter',' ;','headerlines',1)
>
> but in octave I get the following error message
>
> error: some element undefined in return list.
>
> Can anyone help me in detecting the problem?
Which Octave version do you use?
In octave-3.8.2 the following just works:
[L1, L2, L3] = textread ('Graph.dot', '%u->%u [weight=" %d"];',
'headerlines', 1)
L1 =
2
3
4
5
6
7
8
9
L2 =
1
2
3
1
5
3
1
1
L3 =
259178
732180
137337
521430
87498
912756
191335
329365
In a debug session I saw that your second format conv. specifier ("%*s2")
was giving problems. Replacing it by a literal solved that. It may be a bug
but at least there's a workaround.
Next up, you do not seem to need ";" as delimiter, and the last format conv.
specifier either ("%*s") is superfluous - it even clobbers up parsing of
your text file in Octave.
Apparently Matlab is more forgiving and that can lead to problems (we quite
often see similar problems, caused by scripts/files with somewhat wonky
syntax accepted by ML but not by Octave).
Philip
--
View this message in context:
http://octave.1599824.n4.nabble.com/textread-proeblem-tp4666132p4666138.html
Sent from the Octave - General mailing list archive at Nabble.com.