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!
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.