필터 지우기
필터 지우기

Way to break matlab code string into array of sections

조회 수: 1 (최근 30일)
Aditya Jain
Aditya Jain 2015년 10월 21일
댓글: Aditya Jain 2016년 8월 25일
Suppose I have the following string:
a = 2
a =3
t = 0:.1:pi*4;
y = sin(t);
for k = 3:2:9
y = y + sin(k*t)/k;
if ~mod(k,3)
display(sprintf('When k = %.1f',k));
plot(t,y)
end
end
If you notice the third section has nested sections.
I want the output to be
[ 'a = 2', 'a=3' , 't = 0:.1:pi*4;
y = sin(t);
for k = 3:2:9
y = y + sin(k*t)/k;
if ~mod(k,3)
display(sprintf('When k = %.1f',k));
plot(t,y)
end
end']
How can achieve this using string manipulation?
Using normal regex with '%%' will break the 3rd section into 3 sections.

채택된 답변

goerk
goerk 2015년 10월 21일
편집: goerk 2015년 10월 21일
You can try something like this:
result = regexp(str,'^%%','split','lineanchors')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by