How do I iterate variable names when loading dicom files?

조회 수: 4 (최근 30일)
NFC
NFC 2021년 8월 3일
댓글: Stephen23 2021년 8월 3일
I have 10 dicom files in a folder with names ["dicom1200.dcm","dicom1201.dcm"..."dicom1209.dcm"]. For each of these files, I want to load the dicominfo as a variable named dicom1200info, dicom1201info, etc. How do I do this so that the variable names are set iteratively? I am not sure cell arrays would work here because each dicominfo is itself a whole struct. I have heard it said that I should not be doing this, but I am not aware of any workarounds (additionally, i just need the task done and computational expense is not an issue).
Thanks
  댓글 수: 1
Stephen23
Stephen23 2021년 8월 3일
"How do I do this so that the variable names are set iteratively?"
Just use a cell array.
"I am not sure cell arrays would work here because each dicominfo is itself a whole struct."
A cell array works for me without any problem:
C = {struct('A',1:3);struct('A',4:6)}
C = 2×1 cell array
{1×1 struct} {1×1 struct}
"I have heard it said that I should not be doing this, but I am not aware of any workarounds"
Indexing into cell arrays is not a "workaround", it is basic MATLAB.

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2021년 8월 3일
files = dir('*dcm') ;
N = length(files) ;
for i = 1:N
file = files(i).name ;
% do what you want
end

카테고리

Help CenterFile Exchange에서 Read and Write Image Data from Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by