Reading a string datafile line by line

11 ビュー (過去 30 日間)
Ignacio
Ignacio 2015 年 5 月 31 日
コメント済み: Ignacio 2015 年 5 月 31 日
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 Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by