controlling the directory of the output file?!

조회 수: 1 (최근 30일)
Ano
Ano 2017년 10월 27일
댓글: Ano 2017년 11월 24일
Hello! I have three files, 'originFile' which contains file1 and file2 , I would like to know how can I force Matlab to save the output files from funct1 in file1 into file1 and not in the 'originFile' ?! Thank you!
  댓글 수: 2
Rik
Rik 2017년 10월 27일
This depends on how you are writing it exactly, but every writing function I know of accepts explicit paths (i.e. full paths, including the drive letter).
A more specific answer is not possible, as you told nothing of how your code works.
Ano
Ano 2017년 10월 27일
Hi @Rik Wisselink, my code is spreaded out into two files file1 and file2 within each file there is some functions calling each other, and for organization purposes I would like to save the output files from functions in file1 in that same file. Thank you!

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

채택된 답변

Rik
Rik 2017년 10월 27일
You can get the filename and name of the current function with dbstack:
ST = dbstack('-completenames');
ST =
file: 'C:\myProject\myfile.m'
name: 'myfile'
line: 2
If you have multiple functions (which will almost always be the case), ST will be a struct array, so ST(1).file would be what you need.
As a last remark: you must have an interesting function structure if subfunctions in one file can access subfunctions in another file. But that is your decision to make of course.
  댓글 수: 3
Rik
Rik 2017년 10월 31일
(If my answer solved your question, please mark it as accepted answers.)
Normally, if you have a subfunction in a file, functions outside of that file can not call that function. You can circumvent this with something like fh = str2func(fid);[varargout{1:nargout}] = fh(varargin{:});
In short, I can't really imagine a function structure that makes sense and works the way you describe.
Ano
Ano 2017년 11월 24일
Hello, I just wanted to add another alternative that worked for me for those who might face the same problem. I have added to the function funct1 ,which I would like to get its out put , the following code line:
cd('./file1')

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

추가 답변 (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