scriptで絶対パ​スで複数ファイルを作​成・保存する際に,フ​ァイル名の一部に指定​した文字列を一括で含​めたい

14 views (last 30 days)
SK
SK on 24 Sep 2020
Commented: michio on 25 Sep 2020
scriptで作成した複数のfigureを絶対パスで指定したフォルダ内に保存したい場合に,ファイル名の一部に同一文字列を一括で挿入することはできますか?
例えば,script上で「~~~_figure_1」,「~~~_figure_2」,「~~~_figure_3」という名前でfigureフォルダを作成・保存するときに,
一番最初に「Test-1」という文字列を作成しておいて,「~~~」の部分を一括で「Test-1」に置換して「Test-1_figre_1」といったファイルを作成・保存することは出来るでしょうか?
savefig('C\Useres\Documents\保存先フォルダ名\~~~_figure_1)
などとコマンド保存しようとすると'C\以降は文字列認識のためうまく挿入等ができませんでした.

Answers (1)

michio
michio on 24 Sep 2020
正規表現を使ってもよいですが、string 型の操作で例えば以下のようなことはできますが、用途に合いそうでしょうか?
>> str = ["asdfadsfa_figure_1", "asdfasdgfd_figure_2", "wergrgafasd_figure_3"]
str =
1×3 string 配列
"asdfadsfa_figure_1" "asdfasdgfd_figure_2" "wergrgafasd_figure_3"
>> "Test-1" + "_figure" + extractAfter(str,"figure")
ans =
1×3 string 配列
"Test-1_figure_1" "Test-1_figure_2" "Test-1_figure_3"
  2 Comments
SK
SK on 25 Sep 2020
教えていただいたstring配列を色々といじってみてたところ,やりたいことができるようになりました.
大変助かりました.
どうもありがとうございました.
michio
michio on 25 Sep 2020
よかったです!

Sign in to comment.

Categories

Find more on Text Analytics Toolbox in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!