MATLAB Answers

huda nawaf

how read this txtfile?

Asked by huda nawaf
on 21 Jul 2012


if i have txt file with different types of values. how i can read it

the file has these information: 1|Toy Story (1995)|01-Jan-1995|||0|0|0|1|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0

2|GoldenEye (1995)|01-Jan-1995|||0|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0

what i need is just access to last 19 items .i.e i need access to binary no.

how can do that?

  1 Comment

Mus Bohr
on 21 Jul 2012

textscan or textread.



No products are associated with this question.

1 Answer

Answer by per isakson
on 21 Jul 2012
Edited by per isakson
on 21 Jul 2012
 Accepted answer

This is a start. Add a loop and fgetl.

str = '1|Toy Story (1995)|01-Jan-1995|||0|0|0|1|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0';
cac = regexp( str, '(\|(1|0)){3,}', 'match' ) ;
tmp = cac{:}(2:end); % strip off first bar
val = textscan( tmp, '%u', 'Delimiter', '|', 'CollectOutput', true );


  1 Comment


many many thanks for u

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!