Effacer les filtres
Effacer les filtres

Problem with defining a path to a MATLAB function

2 vues (au cours des 30 derniers jours)
Demy
Demy le 16 Déc 2022
Commenté : Demy le 16 Déc 2022
I've got a problem in defining a path in load_untouch_nii function. My code looks like this:
%define the path to the current folder
path = ('~/Desktop/Data/pat01_t1/');
%load the nifti images
Brain = load_untouch_nii(path, 'Brain.nii');
When I try to run the above code I get the following error:
Error using load_nii_hdr (line 47)
Cannot find file "~/Desktop/Data/pat01_t1/.hdr".
Error in load_untouch_nii (line 103)
[nii.hdr,nii.filetype,nii.fileprefix,nii.machine] = load_nii_hdr(filename);
Error in Brain_segmentations (line 4)
data = load_untouch_nii(path, 'Brain.nii');
Can someone please help?

Réponse acceptée

Stephen23
Stephen23 le 16 Déc 2022
Modifié(e) : Stephen23 le 16 Déc 2022
P = '~/Desktop/Data/pat01_t1/'; % do NOT use PATH as a variable name.
Brain = load_untouch_nii(fullfile(P,'Brain.nii'));
Most likely the function you are calling requires the filename (whether absolute or relative) as one input argument, not two separate inputs.
  1 commentaire
Jan
Jan le 16 Déc 2022
Modifié(e) : Jan le 16 Déc 2022
Two brains - one thought. I love it.

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 16 Déc 2022
Maybe you mean:
folder = '~/Desktop/Data/pat01_t1/';
Brain = load_untouch_nii(fullfile(folder, 'Brain.nii'));
The first input is the file name, not just the folder. fullfile joins the names of the folder and the file.
Note that "path" is a bad choice for a variable, because this shadows an important built-in function. This can cause very strange side-effects during debugging.
  1 commentaire
Demy
Demy le 16 Déc 2022
Great! Thank you both guys :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Filtering and Enhancement dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by