[英]gnuplot with a variable in the path to a file
我需要在不同的設備上運行gnuplot腳本。 進入特定目錄后,設備上的文件結構相同,但是這些目錄的路徑不同。 我認為我需要在路徑名中有一個變量,可以根據所使用的設備進行更改。
我認為以下方法會起作用, 因為我在這里找到了類似的東西 ,但沒有:
path_to_directory="/desktop/path/to/directory"
# path_to_directory="laptop/path/to/directory"
# the line above is commented out but it can be included
# if I want to switch from my desktop to my laptop
path_to_file="$path_to_directory/path/to/file"
plot path_to_file ...
警告消息:跳過不可讀的文件“ $ path_to_directory / path / to / file”
您是否知道如何在gnuplot腳本的路徑中包含變量,以便在路徑之間輕松切換?
謝謝。
在gnuplot中,您不像在bash中那樣使用$
來指示變量。 您將使用點進行串聯操作:
path_to_directory="/desktop/path/to/directory"
path_to_file=path_to_directory."/path/to/file"
您只需要將兩個字符串變量與串聯即可.
運營商:
path_to_directory = "/desktop/path/to/directory"
path_to_file = path_to_directory . "/path/to/file"
plot path_to_file ...
您還可以定義可以覆蓋的默認路徑:
default_path_to_directory = "/desktop/path/to/directory"
if (!exists("path_to_directory")) path_to_directory = default_path_to_directory
path_to_file = path_to_directory . "/path/to/file"
plot path_to_file ...
現在,您可以覆蓋path_to_directory
但不能覆蓋:例如,在調用gnuplot -e "path_to_directory='...'" script.gp
類的gnuplot -e "path_to_directory='...'" script.gp
或使用配置文件時。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.