How to pass a variable to a UNIX command, e.g. sed inside a matlab script?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to replace the value assigned to a parameter (say old) inside an FEA input file 'input_file' with a new value (say new) and save the modified file to 'output_file' with the following unix command.
for i=1:n
new = modulus(i)
!sed 's!\$ .*!'"old = new"'!' <input_file >output_file
end
This command is inside a *.m script file. It doesn't work and replaces the value of old with string 'new' and not the value of modulus(i). How can we pass a real variable to a unix command inside a matlab script?
0 comentarios
Respuestas (1)
José-Luis
el 20 de Dic. de 2016
I don't think sed is integrated to Matlab so, yes, you'd need a system() call.
The power of regex is directly at your hands in Matlab for string manipulations.
But if all you want to do is change filenames, you don't really need sed. I would just use movefile().
2 comentarios
José-Luis
el 20 de Dic. de 2016
Editada: José-Luis
el 20 de Dic. de 2016
I misunderstood what you meant.
My point still stands though. sed is not an integral part of Matlab. If you want to use that, then you could call it through system().
An alternative is to load the file, do the changes you need (e.g. regexp()) and save it under the new name.
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!