changing directory in matlab

조회 수: 10 (최근 30일)
mohammad
mohammad 2011년 8월 31일
댓글: Ahmed Aisa 2016년 12월 15일
does anyone know how to change matlab directory? for example now current directory is f:\a\b\c and i want to change to f:\a but without telling f:\ . in other words, only with giving 'a' (the name of folder) and without telling f:\ , MATLAB itself find f:\a. does anyone know how can i use this: in this link: http://www.mathworks.com/matlabcentral/fileexchange/12002-jump there is a m-file for changing MATLAB current directory to the folder matching the specified pattern. But i cant use this. what can i do ?
  댓글 수: 1
Ahmed Aisa
Ahmed Aisa 2016년 12월 15일
Hello i would like to someone help me for design system like Electrolyzer with Hydrogen tank. Best regards

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

채택된 답변

Daniel Shub
Daniel Shub 2011년 8월 31일
What about something like:
x = pwd;
drive = x(1:3);
cd([drive, 'a']);
or
cd([drive, 'a\b']);
This will work assuming you are currently in drive "f" and want to stay in drive "f". You could also change to drive "f" and then do:
x = pwd;
drive = x(1:3);
jump = @(newpath)cd([drive, newpath]);
jump('a');
and
jump('a\b');
  댓글 수: 4
Daniel Shub
Daniel Shub 2011년 8월 31일
Can you add the three lines to the beginning of your mfile? If your mfile is a script you can execute the three lines beforehand. If your mfile is a function you can pass it the function handle "jump", but this will still require you to edit you mfile.
mohammad
mohammad 2011년 8월 31일
you are right i did it and now works
thanks a lot

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

추가 답변 (1개)

Friedrich
Friedrich 2011년 8월 31일
Hi,
I think this m file won't help much here since it uses the which commands to search for files with a specific name and which are on the MATLAB path only.
Are your folders, where you like to jump to, on the MATLAB path? If so, you could parse the MATLAB path for it and jump to it.
  댓글 수: 1
mohammad
mohammad 2011년 8월 31일
Hi dear
thanks for replying
its on the current directory, but i need this: only with giving folder name ( and not giving drive name (f:) ), directory has been changed
for example
current directory is: f:\a\b\c (and in 'b' folder are two others folder: 'c' and 'd')
now i want to change to this directory with giving only 'd': f:\a\b\d

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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by