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!
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Collections 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!