Borrar filtros
Borrar filtros

Running a certain script section from other m-file?

3 visualizaciones (últimos 30 días)
Ion
Ion el 9 de Dic. de 2013
Respondida: Walter Roberson el 9 de Dic. de 2013
Hi,
let´s say that I would have two matlab m-files: A and B.
My need is to run some certain part (section) in m-file A, but this would be run by m-file B. Is this possible.
It´s like the section in A would be like a "function" that m-file B calls. However, I wouldn´t like to make the section in A as a function. I would like to keep it as a certain section that I can run with "run section" button if I want to in m-file A.
Is this even possible to run a section as "remote"?

Respuestas (1)

Walter Roberson
Walter Roberson el 9 de Dic. de 2013
Yes. Your script could read A.m as a bunch of strings, extract the lines of interest, and then eval() those lines.
If you want to stick with scripts, I suggest moving those lines out of A.m into A_sub.m, and in A.m replace them with the line
A_sub
to run the A_sub script within the context of A . You would use the same line in B.
This is not the same as creating a function: function files need to start with the word "function"

Categorías

Más información sobre Environment and Settings 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