Continue Long Statements on Multiple Lines

조회 수: 4 (최근 30일)
Zadmehr Sg
Zadmehr Sg 2020년 12월 11일
답변: dpb 2020년 12월 11일
Hi all,
I would be thankful if one can help me solve this issue.
I have a .txt file with a large number of lines (i.e 87471) .
A snapshot is as follows.
Sys_7899 1=0.21 2=0.31 3=0.32 4=0.77 5=0.97 6=0.1 7=0.31 8=0.71
9=0.92 10=0.36 11=0 13=0.147 14=0.55
Sys_7900 1=0.41 2=0.53 3=0.80 4=0.69 5=0.34 6=0.94 7=0.1 8=0.48
9=0 10=0.4 11=0 12=0.21
Sys_7901 1=0.41 2=0.53 3=0.84 4=0.69 5=0.34 6=0.94 7=0.11
Sys_7902 1=0.56 2=0.13 3=0.89 4=0.11 5=0.11 6=0.12 7=0.17
In fact, the no. of samples are not the same (in each col.)
How can I add the second lines to the end of the first lines when the no. of samples goes more 8? In fact, I want to have all samples in just one and not given them into two lines for each sys like.
Sys_7900 1=0.41 2=0.53 3=0.80 4=0.69 5=0.34 6=0.94 7=0.1 8=0.48 9=0 10=0.4 11=0 12=0.21

답변 (1개)

dpb
dpb 2020년 12월 11일
ix=find(~contains(txt,'Sys'));
>> arrayfun(@(ix) join(txt(ix-1:ix),1),ix)
ans =
2×1 cell array
{'Sys_7899 1=0.21 2=0.31 3=0.32 4=0.77 5=0.97 6=0.1 7=0.31 8=0.71 9=0.92 10=0.36 11=0 13=0.147 14=0.55'}
{'Sys_7900 1=0.41 2=0.53 3=0.80 4=0.69 5=0.34 6=0.94 7=0.1 8=0.48 9=0 10=0.4 11=0 12=0.21' }
>>

카테고리

Help CenterFile Exchange에서 Dynamic System Models에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by