Reading a string datafile line by line

12 次查看(过去 30 天)
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!

采纳的回答

per isakson
per isakson 2015-5-31
Try
cac = textscan( fid, '%s', 'Delimiter', '\n' )
  1 个评论
Ignacio
Ignacio 2015-5-31
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by