How to write a script to edit another script ?

3 visualizaciones (últimos 30 días)
Rodriguez Pham
Rodriguez Pham el 14 de Ag. de 2015
Comentada: Steven Lord el 14 de Ag. de 2015
I have a script lets call it scriptA, that contains parameter names and assigned values. I am trying to write a script (scriptB) that will edit scriptA by changing both the parameter names and the values. I will be reading in a excel spreadsheet that contains the names and values that I will be assigning. How should I go about this?

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 14 de Ag. de 2015
doc fprintf
Allows you to write text files.
  1 comentario
Rodriguez Pham
Rodriguez Pham el 14 de Ag. de 2015
I see, I have the idea of writing file now, but in terms actually making the edits, im curious whats the best way i should go about it.
For example if I have the line
temp = 2974;
if I replace the value 2974. I would have to first find where temp is in my script(which i can do) would I then search for the index after the '=' symbol and then grab until ';' symbol and replace that?

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 14 de Ag. de 2015
Why not make scriptB into a function that accepts input arguments and/or reads in a data file in a known format and pass the varying parameters into that function?
  2 comentarios
Rodriguez Pham
Rodriguez Pham el 14 de Ag. de 2015
I kind of understand what you are saying, but i need a little more elaboration. I am still a bit new to matlab.
Steven Lord
Steven Lord el 14 de Ag. de 2015
Rather than writing a script:
PLACEHOLDER_NAME = 2*PLACEHOLDER_VALUE
whose PLACEHOLDER_* entries you replace with contents from another file, instead write a function:
function y = timesTwo(x)
y = 2*x;
You can then call timesTwo wherever you would invoke the script:
z = timesTwo(17);
where 17 is data you read from a file or something.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by