Index exceeds the number of array elements (0). Error in ROI_timeco​urse_DICOM​_v2_0 (line 20) FullFileName = FileName(1:suffix(1)-5);

2 vues (au cours des 30 derniers jours)
Hello All,
Would really appreciate some help. I have a script that enables me to readin a series of DICOM images fromMRI scanner, select regions of interest and generate T2* signal intensity curves.
I keep getting this error.
>> ROI_timecourse_DICOM_v2_0
Have you saved ROIs to use in this subject? [y/n]: n
Would you like to redo any of the ROIs? [y/n]: n
Index exceeds the number of array elements (0).
Error in ROI_timecourse_DICOM_v2_0 (line 20)
FullFileName = FileName(1:suffix(1)-5);
The code is:
clear all
close all
%%***********************************************************************%%
%% READS IN A SERIES OF DICOM IMAGES %%
%% CREATES AND SAVES OR LOADS IN SAVED MASK ROIS %%
%% PLOTS TIME COURSES OF THE ROIS %%
%% Written by Wesolek (Roman Wesolowski) %%
%% contact me if you have problems modifying this script. %%
%%***********************************************************************%%
%% Name and path of outcoming and incoming files
%path='/Volumes/DOCS/DATA/studies/';
%cd(path)
ROIcheck=input('Have you saved ROIs to use in this subject? [y/n]: ','s');
ROIcorr=input('Would you like to redo any of the ROIs? [y/n]: ','s');
[FileName,PathName] = uigetfile({'*','*'},'Input the first DICOM functional image (exported from Osirix)');
im4D_info=dicominfo(strcat(PathName,FileName));
suffix=strfind(FileName,'.');
FileName = FileName(1:suffix(1)-5);
dyns=im4D_info.NumberOfTemporalPositions;
name_dir=dir(strcat(PathName,FileName,'*'));
name_dir=name_dir(1:dyns);
datefile=num2str(char({name_dir.name}));
im4D=zeros(im4D_info.Rows,im4D_info.Columns,im4D_info.Private_2001_1018,dyns);
h=waitbar(0,'Loading Files...');
for i=1:dyns
im4D_info_=dicominfo(strcat(PathName,name_dir(i).name));
im4D_info_.BitsAllocated=32;
im4D(:,:,:,i)=im4D_info_.RescaleSlope*dicomread(im4D_info_);
waitbar(i/dyns,h,strcat('Loading Files... ',num2str(round(i/dyns*100)),' %'));
% fprintf(1,'File Name: %s \n',name_dir(i).name); %prints out all the names of loaded files
end
close(h)
fprintf(1,'Total of %d functional files loaded \n',i);
colour_map='rkbmgrkbmgcy';
cd(PathName)
if ((ROIcheck=='n')||(ROIcorr=='y'))
[FileNameA,PathNameA] = uigetfile({'*','*'},'Input the first DICOM anatomical image (exported from Osirix)');
imAnat_info=dicominfo(strcat(PathNameA,FileNameA));
suffix=strfind(FileNameA,'.');
FileNameA=FileNameA(1:suffix(1)-5);
dyns=imAnat_info.NumberOfTemporalPositions;
if (dyns==1)
h=waitbar(0,'Loading Files...');
slc=imAnat_info.Private_2001_1018;
name_dir1=dir(strcat(PathNameA,FileNameA,'*'));
name_dir1=name_dir1(1:slc);
datefile=num2str(char({name_dir1.name}));
for i=1:slc
imAnat(:,:,i)=dicomread(strcat(PathNameA,name_dir1(i).name));
% fprintf(1,'File Name: %s \n',name_dir1(i).name);
waitbar(i/slc,h,strcat('Loading Files... ',num2str(round(i/slc*100)),' %'));
end
Can somebody help me correct this error please.

Réponses (1)

Guillaume
Guillaume le 27 Nov 2019
Most likely, strfind(FileName, '.') didn't find a . so suffix is empty and of course suffix(1) is invalid since index 1 is more than the 0 elements in suffix (as the error message tells you).
  2 commentaires
LAWEN KARIM
LAWEN KARIM le 27 Nov 2019
Thank for the answer.
So how do I correct it?
Guillaume
Guillaume le 27 Nov 2019
Modifié(e) : Guillaume le 27 Nov 2019
Select a file that has a . in it when prompted by uigetfile?
Change your code so it doesn't look for a . ?
Change your code so it check if the file name has a . in it and react accordingly?
I can't tell you how to fix it since there's no comment explaining what the code is supposed to do.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by