Effacer les filtres
Effacer les filtres

Cannot find file that exists for second variable

1 vue (au cours des 30 derniers jours)
nines
nines le 9 Mar 2024
Modifié(e) : Stephen23 le 10 Mar 2024
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!

Réponse acceptée

Stephen23
Stephen23 le 9 Mar 2024
Modifié(e) : Stephen23 le 10 Mar 2024
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)

Plus de réponses (0)

Catégories

En savoir plus sur Time Series Events dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by