如何在 matlab 中访问 windows 相对路径(例如 %userprofile%)?

How to access windows relative paths (e.g. %userprofile%) in matlab?

我想在 matlab 中获取相对路径(例如 'C:/Users/thisuser/THATFOLDER')。我在你可以使用 ~ 的 unix 机器上阅读,但是我正在 windows 系统上工作。

有解决办法吗?赞赏

您可以使用函数 system:

获取完整路径

例如

[~,cmdout] = system('echo %APPDATA%')

应该给你完整的 appdata 路径。

您可以使用以下方式获得一般 windows 环境设置:

userFolder = getenv ( 'userprofile' )

所以要获得 THATFOLDER 使用:

fullfile ( userFolder, 'THATFOLDER' )

一行:

fullfile ( getenv ( 'userprofile' ), 'THATFOLDER' );