Storing data from for loop

2 ビュー (過去 30 日間)
Shaun
Shaun 2015 年 1 月 27 日
編集済み: Stephen23 2015 年 1 月 27 日
Hi all,
I'm new to Matlab and trying to create a for loop that will save information gathered from a DICOM file into a mtrix for further use. My code so far is as follows...
[FileName PathName] = uigetfile('*.*','Select DICOM File', 'MultiSelect','on');
im1=dicomread([PathName FileName{1}]);
[r c]=size(im1);
I=[];
order=[];
for s=1:length(FileName)
info=dicominfo([PathName FileName{s}]);
order=info.SliceLocation;
I(:,:,s)= [PathName, FileName(s), order]
end
I get the following error when running the code...
Conversion to double from cell is not possible.
Error in Untitled3 (line 11)
I(:,:,s)= [PathName, FileName(s), order]
Any help would be much appreciated. I apologise if any forum rules have not been followed.
  1 件のコメント
Stephen23
Stephen23 2015 年 1 月 27 日
Note it is recommended to use fullfile rather than simply concatenating the path and filename strings.

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2015 年 1 月 27 日
編集済み: Stephen23 2015 年 1 月 27 日
You define I to be of class double with the line I=[];, and you then try to allocate some data into it that is of class cell. Thus the error message.
One alternative it to not preallocate this variable (or even the variable order) and just refer to them first in the loop:
[FileName,PathName] = uigetfile('*.dcm','Select DICOM File', 'MultiSelect','on');
for n = numel(FileName):-1:1
dcinfo = dicominfo(fullfile(PathName,FileName{n}));
%order = dcinfo.SliceLocation; % not in the documentation.
out{n} = fullfile(PathName,FileName(n));
end
Note how I looped from N->1, so that the cell array is correctly sized from the very first iteration (a kind of preallocation ).

その他の回答 (1 件)

Sara
Sara 2015 年 1 月 27 日
Try replacing FileName(s) with FileName{s}

カテゴリ

Help Center および File ExchangeDICOM Format についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by