Full File Path Quotation Marks (Double vs Single)

34 ビュー (過去 30 日間)
Peter Cook
Peter Cook 2017 年 6 月 8 日
コメント済み: Walter Roberson 2017 年 6 月 9 日
A small thing that I often work around is changing file path names enclosed in double quotes to single quotes to load them into MATLAB.
In Windows I like to get a full file path (for some file that is not in my current MATLAB directory, or on PATH) with right-click + Copy As Path, which dumps a string like this on the clipboard: "C:\Users\Peter\Desktop\Pinnacle\Folder1\Folder2\Folder3\allMinima645.mat" which I need to change to this form to use the load function in MATLAB: 'C:\Users\Peter\Desktop\Pinnacle\Folder1\Folder2\Folder3\allMinima645.mat'
In python (which has its own preferred directory/path format) I can load the same using the "r" flag to tell it that I'm working with regular text formatting:
import scipy.io as sio
sio.loadmat(r"C:\Users\Peter\Desktop\Folder1\Folder2\Folder3\allMinima645.mat")
which I find slightly less cumbersome than this:
load(regexprep('"C:\Users\Peter\Desktop\Folder1\Folder2\Folder3\allMinima645.mat"','"',''))
Is there a MATLAB equivalent of pythons "r" flag (or another way to work with this)?
  3 件のコメント
Peter Cook
Peter Cook 2017 年 6 月 8 日
R2015b; What about it changed in 2016b & 2017a?
Walter Roberson
Walter Roberson 2017 年 6 月 9 日
R2016b added support for string objects -- character strings that can be referenced as single entities instead of having to use character vectors. string objects are displayed with double-quotes. String objects could be created from character vectors, but in R2016b there was no direct way to create a string object with specific content.
R2017a added allowing double-quotes on input to create string objects. So for example,
load("C:\Users\Peter\Desktop\Folder1\Folder2\Folder3\allMinima645.mat")
is valid in R2017a but not in R2016b.

サインインしてコメントする。

採用された回答

Jan
Jan 2017 年 6 月 9 日
You could create your own function to remove the double quotes.
function S = Unquoted(S)
if length(S) >= 2
if S(1) == '"'
S(1) = [];
end
if S(end) = '"'
S(end) = [];
end
end
  2 件のコメント
Peter Cook
Peter Cook 2017 年 6 月 9 日
A custom function seems to be the best solution since I'm still running 2015b. Thank you.
Walter Roberson
Walter Roberson 2017 年 6 月 9 日
" cannot appear inside a file name https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx so you could simplify this to
Unquoted = @(S) S(S ~= '"')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by