%%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 Exchange에서 Text 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