Cannot find file that exists for second variable

1 次查看(过去 30 天)
Ok so I have the following flow_preprocess function:
function flow_preprocess(timeseries,T1w)
%%
% FORMAT flow_preprocess(timeseries,T1w))
%
% INPUTS the names of the timeseries, T1w
% OUTPUTS the names of the newfiles created
%
if nargin < 2
fprintf('nargin is less than 2\n');
error('The minimal pipeline includes a time series and a T1w image.');
else
if ~exist('timeseries','file')
fprintf('Cannot find the file: %s\n', timeseries);
error('Cannot find %s', timeseries);
end
if ~exist('T1w','file')
fprintf('Cannot find the file: %s\n', T1w);
error('Cannot find %s', T1w);
end
end
end
and I am getting a very simple error where it is exiting at the following:
if ~exist('T1w','file')
fprintf('Cannot find the file: %s\n', T1w);
error('Cannot find %s', T1w);
end
Producting the following error:
Cannot find the file: /path/to/subject/sub-02_file1.nii.gz
However, when I pass the same file as 'timeseries', I do not get the error. Additionally, I can 'ls' the file, and the folder has been added to my path.
It is such an odd bug, does any one have any suggestions of what could be causing matlab not being able to recognize the file that exists and it on the path?
Thanks a ton!

采纳的回答

Stephen23
Stephen23 2024-3-9
编辑:Stephen23 2024-3-10
Your code is looking for a file literally named TIMESERIES:
if ~exist('timeseries','file')
whereas what you want to do is use the variable TIMESERIES like this:
if ~exist(timeseries,'file')
Printing the content of TIMESERIES in the error message misleads you into thinking that is what EXIST has just looked for... but it isn't. Tip: use ASSERT instead of IF and ERROR:
assert(exist(timeseries,'file'), 'Cannot find the file: %s', T1w)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Time Series Collections 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by