Reputation: 9909
In a folder, I have both my .m
file that contains the script and one imaging .dcm
file that is the target of my analysis.
Folder structure:
Folder1/analysis.m
Folder1/meas_dynamic_123.dcm
Folder1/meas_123.dcm
Folder1/meas_345.dcm
My script (analysis.m) begins as follows:
target =''; <== here should go only the filename that contains 'dynamic'
example: meas_dynamic_123.dcm
txt = dir(target);
// etc
So I'm wondering if there is a way of when running analysis.m
it will:
automatically search the folder it's in,
grab the filename of file containing string dynamic
in the name,
insert its name into target
variable
continue running the script
Does anyone have any pointers on how to achieve this? Using ffpath
?
Upvotes: 0
Views: 99
Reputation: 24127
Instead of which(scriptname)
, consider using mfilename('fullpath')
, which will directly give you the full path of the running m-file. Using which
might break if you had multiple commands of the same name shadowed on the path.
Upvotes: 0
Reputation: 1802
Assume you are not in Folder1
and you need to find it:
script_name = 'analysis';
script_full_path = which(script_name); % get full path of the script
script_dir = fileparts( script_full_path ); % get the directory of the script
file_list = dir( [script_dir '/*dynamic*']);
name_list = {file_list.name};
name_list
will be a cell array containing the file names with the keyword 'dynamic'.
Upvotes: 1