0

I'm trying to read numbers in a text file line by line. Each line in the file is like this:

(563,478),(630,573),1

I tried the command below but it didn't work:

textscan(f1, '%d%d%d%d%d', 'delimiter', ',');

How can I skip the ")" and "("? I want to read only the numbers.

Here is one of the text files. (the red button)

Hadi GhahremanNezhad
  • 2,377
  • 5
  • 29
  • 58

1 Answers1

2

You can do:

textscan(f1, '(%d,%d),(%d,%d),%d')

to scan a file or

sscanf(f1, '(%d,%d),(%d,%d),%d')

to scan a string.

Usage(tested in Octave):

f1 = fopen('005.txt','r');
c=textscan(f1, '(%d,%d),(%d,%d),%d');
fclose(f1);


f1 = '(401,596),(443,636),1'
sscanf(f1,'(%d,%d),(%d,%d),%d')
rahnema1
  • 15,264
  • 3
  • 15
  • 27