Filter löschen
Filter löschen

Editing values in Matlab script from Bash script

1 Ansicht (letzte 30 Tage)
g
g am 18 Okt. 2018
Kommentiert: Steven Lord am 18 Okt. 2018
Let's say I have a script called Histogram.m that performs a variety of functions.
It has a variable named Detect that can be set to 0,1, or 2. It is currently set to 0 in the script. Let's say though that I have an Bash script (called RunHist) which runs this script through the following scheme:
matlab -nodesktop -nodisplay -r "Histogram; exit"
I want to have the option in RunHist to change the value of Detect to 1 or 2 before running Histogram.m. How would I implement this? Thanks!

Antworten (1)

Walter Roberson
Walter Roberson am 18 Okt. 2018
Bearbeitet: Walter Roberson am 18 Okt. 2018
Have a second script that sets the value of the variable and alter that script as needed, such as with echo redirected to a file.
Or have your script read the value from a file, and alter the file as needed.
Or make your script into a function that expects the value to be passed in.
Or use input() in the script and use shell facilities to send the value into stdin.
Or use sed or similar to alter the script file.
  1 Kommentar
Steven Lord
Steven Lord am 18 Okt. 2018
In addition to Walter's suggestions, you might want to rename your script. There's a histogram function in MATLAB.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by