How to navigate between directories during program execution?

조회 수: 6 (최근 30일)
Yashar Mehmani
Yashar Mehmani 2011년 7월 7일
편집: Yashar Mehmani 2017년 10월 27일
I have a program in which I need to navigate from directory to directory (with the number of such directories being a variable), and read a bunch of files and execute a bunch of function files in them. Part of the reason they are put in different directories is that the M-files in these directories have the same names. My question is how:
  1. without changing the current directory (using the cd command)and
  2. without adding and removing paths with addpath and rmpath
Can I access these files selectively without creating conflict. Meaning every single time inside the program when I want to execute a function or read a file I could just do it knowing the full path of that folder. So all there would be known to you at each time is the full directories of the folders where these files are located.
One last note: Although I said the number of such directories is a variable, I know exactly which level they are located at, equivalently I know their full path every time at that juncture in my program (If this helps further ==> great, otherwise ==> ignore this last comment).
Thank you
  댓글 수: 3
Yashar Mehmani
Yashar Mehmani 2011년 7월 7일
Yes that would help with reading the files, but how do I reach the function files?
per isakson
per isakson 2017년 9월 15일
편집: per isakson 2017년 9월 15일
For some reason this question appeared as Most Recent.
AFAIK: "[...] I want to execute a function [...] I could just do it knowing the full path of that folder" That is not possible, not without manipulating the search path or the current directory.
Had it been package folders it might be possible. Given
...\folder_in_the_search_path\+mypack\+mysubpack\myFcn.m
this call is possible
out = mypack.('mysubpack').myFcn( inarg )
However, I fail to find support in the documentation.

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

답변 (1개)

Honglei Chen
Honglei Chen 2011년 7월 7일
Hi Yashar,
The following command may be of your interest
doc run
doc fullfile
HTH
  댓글 수: 1
Yashar Mehmani
Yashar Mehmani 2011년 7월 7일
편집: Yashar Mehmani 2017년 9월 14일
Thank you, but "run" cds to the folder and back. So unfortunately it wouldn't help. And "fullfile" is just a way of concatenating strings to make dirs.

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

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by