textread proeblem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

textread proeblem

Nidjara
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?

Thanks!



Reply | Threaded
Open this post in threaded view
|

Re: textread proeblem

Philip Nienhuis
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
Reply | Threaded
Open this post in threaded view
|

Re: textread proeblem

Nidjara
Thanks a lot!

I'm using Octave 3.62 (it is GNU UPM 8.2 version http://mat.caminos.upm.es/octave/). I'm new in octave and this was the one version I was able to install properly on win 8.1 with GUI.  Will have to move to 3.8.
Reply | Threaded
Open this post in threaded view
|

Re: textread proeblem

Philip Nienhuis
Nidjara wrote
Thanks a lot!

I'm using Octave 3.62 (it is GNU UPM 8.2 version http://mat.caminos.upm.es/octave/). I'm new in octave and this was the one version I was able to install properly on win 8.1 with GUI.  Will have to move to 3.8.
IIRC textread / textscan / strread have been significantly improved as of Octave-3.8.x.
So I'm not surprised it didn't work as you hoped :-)

On http://mxeoctave.osuv.de you can find 3.8.x binaries with a GUI that should work on Windows 8.
You *might* also need a batch file for Octave to have it start properly on Win8x, should be there as well. (AFAIK the thing to check is that the line that actually starts Octave has --line-editing as command line option.)

Philip