開いているスクリプト​のあるフォルダのパス​を得る方法

whichを用いることでそのスクリプトの名前を引数開いているスクリプトのパスを取得できますが,そのスクリプト名がパスに含まれます.
そのスクリプト名を含まない,そのフォルダまでのパスを取得する方法はありますか?
たとえばC:\Users\name\matlab\script.mlxに関して,script.mlxがあるフォルダのパス
C:\Users\name\matlab\を取得する方法が知りたいです.

 Respuesta aceptada

Hiroki Okawa
Hiroki Okawa el 14 de Mayo de 2020
Editada: Hiroki Okawa el 14 de Mayo de 2020

2 votos

fileparts関数はいかがでしょうか。
file = 'H:\user4\matlab\myfile.txt'
[filepath,name,ext] = fileparts(file)
% 以下出力
% filepath = 'H:\user4\matlab'
% name = 'myfile'
% ext = '.txt'

Más respuestas (1)

Kenta
Kenta el 14 de Mayo de 2020

0 votos

こんにちは、extractBefore関数を使うのはいかがでしょうか?以下のようにすればできると思います
path=which(script_name);
extractBefore(script_name)

Categorías

Más información sobre Communications Toolbox en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 14 de Mayo de 2020

Editada:

el 14 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!