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')
  1 件のコメント
Aditya Jain
Aditya Jain 2016 年 8 月 25 日
Good starting point. Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by