フィルターのクリア

Cannot find file that exists for second variable

2 ビュー (過去 30 日間)
nines
nines 2024 年 3 月 9 日
編集済み: Stephen23 2024 年 3 月 10 日
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 Center および File ExchangeTime Series Events についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by