Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read line from a text file as a string in matlab?

Tags:

file-io

matlab

I am trying to read a text file in MATLAB which has a format like the following. I am looking to read the whole line as a string.

 2402:0.099061 2404:0.136546 2406:0.447161 2407:0.126333 2408:0.213803 2411:0.068189

I tried couple of things.

textscan(fid, '%s') reads the line but splits the line into cells at spaces.

fscanf(fid, '%s') reads the line as a string but removes all the spaces.

like image 339
stressed_geek Avatar asked Dec 16 '22 23:12

stressed_geek


1 Answers

fgetl(fid) will do what you're looking for. Newline is stripped off.

like image 51
Peter Avatar answered Dec 31 '22 08:12

Peter