multiple select dicom images for further processing getting error message :Images gets selected but not able to read and filter each images.

[filename,pathname]=uigetfile( ...
{'*.m;*.fig;*.mat;*.mdl','MATLAB Files (*.m,*.fig,*.mat,*.mdl)';
'*.m', 'Code files (*.m)'; ...
'*.fig','Figures (*.fig)'; ...
'*.mat','MAT-files (*.mat)'; ...
'*.mdl','Models (*.mdl)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick a file','Select Files(s)','multiselect','on');
if isequal(filename,0)
disp('User selected Cancel')
else
disp(['User selected', fullfile(filename, pathname)])
end
n = size(filename);
% cd(nameDir);
for x = 1:n(2)
img = dicomread(char(strcat(pwd(), '/', filename(x))));
end

Answers (1)

(1) Use fullfile() to construct the full path; (2) instead of cd'ing to namedir and using pwd(), use pathname as the directory component in fullfile() (3) filename will be a cell array, so dereference it; (4) filename() will probably be a column array instead of a row array, so instead of using the second component of size(), use the first. Or better yet, use length() and then don't worry about whether it is row or column
for x = 1 : length(filename)
img = dicomread( fullfile(pathname, filename{x}) );
end

8 Comments

[filename,pathname]=uigetfile( ...
{'*.m;*.fig;*.mat;*.mdl','MATLAB Files (*.m,*.fig,*.mat,*.mdl)';
'*.m', 'Code files (*.m)'; ...
'*.fig','Figures (*.fig)'; ...
'*.mat','MAT-files (*.mat)'; ...
'*.mdl','Models (*.mdl)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick a file','Select Files(s)','multiselect','on');
if isequal(filename,0)
disp('User selected Cancel')
else
disp(['User selected', fullfile(filename, pathname)])
end
for x = 1 : length(filename)
img = dicomread( fullfile(pathname, filename{x}) );
end
ERROR message:
Cell contents reference from a non-cell
array object.
if more than one image selected Error message: Undefined function 'eq' for input arguments of type 'cell'.
Error in fullfile (line 37) if (f(end)==fs) && (part(1)==fs),
After the if/else/end, but before for loop, add
filename = cellstr(filename);
That will deal with the case where you only select a single file.
yes it works with single file. but i have to select multiple files and process them & store results in excel worksheet.Is it possible to program for multiple selection?
For multiple selection.ERROR message: Undefined function 'eq' for input arguments of type 'cell'.
Error in fullfile (line 37) if (f(end)==fs) && (part(1)==fs),
The code should work. Put in a breakpoint at the "img =" assignment and run your code and select multiple. When it stops, display
class(filename), size(filename)
if filename shows up as cell, then
class(filename{1})

Sign in to comment.

Products

Asked:

on 27 Aug 2013

Community Treasure Hunt

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

Start Hunting!