%%Read file
str=fileread('C:\Users\merve\OneDrive\Masaüstü\S.txt');
%%Remove some annoying segments
str=regexprep(str,'(0 0 0)',' ');
%%Find data in brackets and remove brackets
n='(+|-)?\d+(\.\d+)?(e(+|-)?\d+)?';
str_out=regexp(str,['[(]',n,'\s',n,'\s',n,'[)]'],'match');
str_out=regexprep(str_out, '(', '')';
str_out=regexprep(str_out, ')', '');
num_out=cellfun(@str2num,str_out,'UniformOutput',false);
num_out=cell2mat( num_out )

1 件のコメント

Geoff Hayes
Geoff Hayes 2021 年 12 月 21 日
@merve arpacioglu - what exactly is your question? Please clarify and describe how it relates to the code that you have presented.

サインインしてコメントする。

回答 (1 件)

merve arpacioglu
merve arpacioglu 2021 年 12 月 21 日

0 投票

how to write text file
%%Read file
str=fileread('C:\Users\merve\OneDrive\Masaüstü\S.txt');
%%Remove some annoying segments
str=regexprep(str,'(0 0 0)',' ');
%%Find data in brackets and remove brackets
n='(+|-)?\d+(\.\d+)?(e(+|-)?\d+)?';
str_out=regexp(str,['[(]',n,'\s',n,'\s',n,'[)]'],'match');
str_out=regexprep(str_out, '(', '')';
str_out=regexprep(str_out, ')', '');
num_out=cellfun(@str2num,str_out,'UniformOutput',false);
num_out=cell2mat( num_out )

カテゴリ

ヘルプ センター および File ExchangeText Data Preparation についてさらに検索

製品

リリース

R2021b

質問済み:

2021 年 12 月 21 日

回答済み:

2021 年 12 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by