File path containing %

조회 수: 21 (최근 30일)
Zoltán Csáti
Zoltán Csáti 2015년 8월 13일
댓글: Rahul Sivagaminathan 2022년 4월 18일
I would like to get the path for directories containing % (like %MATLAB_ROOT%, %APPDATA%, etc.) in Windows. However, functions like fileparts cannot interpret the percent sign. Is there a way to make this possible within MATLAB, or the only solution is to call system commands?
Thanks, Zoli

채택된 답변

per isakson
per isakson 2015년 8월 13일
편집: per isakson 2015년 8월 13일
Use getenv, Environment variable to get values of environment variables of the underlying operating system, e.g.
>> getenv('OS')
ans =
Windows_NT
>> getenv('APPDATA')
ans =
C:\Users\poi\AppData\Roaming
%NAME% gets the value of NAME in the Command Prompt, e.g.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\poi>echo %APPDATA%
C:\Users\poi\AppData\Roaming
C:\Users\poi>
And there is the Matlab function, matlabroot
>> matlabroot
ans =
C:\Program Files\MATLAB\R2013b
  댓글 수: 2
Zoltán Csáti
Zoltán Csáti 2015년 8월 14일
I looked into getenv before, but somehow I missed it. Thank you!
Rahul Sivagaminathan
Rahul Sivagaminathan 2022년 4월 18일
I have a follow up question, the getenv('APPDATA') function works if you are writing a program in matlab desktop. I want to compile my matlab program into an exe file using matlab compiler SDK. Once compiled and if i install the program in C drive then getenv('APPDATA') takes me to C\Program Files(x86) .... path but I want to go to C:\Users\poi\AppData\Roaming ... path.
So my question is - how can i get to C\Users\Username\AppData folder if my matlab exe file (compiled using matlab compiler sdk) is installed in C program files. Please help me.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by