Way to break matlab code string into array of sections

1 visualización (últimos 30 días)
Aditya Jain
Aditya Jain el 21 de Oct. de 2015
Comentada: Aditya Jain el 25 de Ag. de 2016
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.

Respuesta aceptada

goerk
goerk el 21 de Oct. de 2015
Editada: goerk el 21 de Oct. de 2015
You can try something like this:
result = regexp(str,'^%%','split','lineanchors')

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by