Reading a string datafile line by line

12 visualizzazioni (ultimi 30 giorni)
Ignacio
Ignacio il 31 Mag 2015
Commentato: Ignacio il 31 Mag 2015
Hi all, I've been trying to read strings from a txt file (a replay script from ICEM actually) line by line but I've been unable to so far.
I want to obtain a string array that each element includes one of the lines of the datafile.
the text file looks like this:
_'ic_boco_solver
ic_boco_clear_icons
ic_csystem_display all 0
ic_csystem_set_current global
ic_boco_nastran_csystem reset
ic_undo_group_end
ic_set_global geo_cad 0 toptol_userset
ic_set_global geo_cad 0.0005 toler
ic_undo_group_begin
ic_geo_new_family GEOM
ic_boco_set_part_color GEOM
ic_point {} GEOM pnt.00 -10,10,0'_
I have only managed to either get each all the text in the same element:
_ic_boco_solveric_boco_clear_iconsic_csystem_display_
or each character separately like this:
_I
c
_
b
o
c
o
_
s
o_
or to get chunks that are separated by empty spaces like this:
_'ic_boco_solver'
'ic_boco_clear_icons'
'ic_csystem_display'
'all'
'0'
'ic_csystem_set_current'
'global'
'ic_boco_nastran_csystem'_
, but I could not get the whole line and only the line.
that was using respectively:
temp1=textscan(fid,'%c')
or
temp2=dataread('file','text.txt','%c')
or
temp2=dataread('file','text.txt','%s')
Every line starts with 'ic_'. Maybe that could help?
Thank you!

Risposta accettata

per isakson
per isakson il 31 Mag 2015
Try
cac = textscan( fid, '%s', 'Delimiter', '\n' )
  1 Commento
Ignacio
Ignacio il 31 Mag 2015
YES!
yet I actually try that before, and tried it again when you just wrote it without success.
I think I was messing things with fopen and fclose, cause as soon as I cleared the workbench and rerunned it, it worked.
Thank you!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by