Having trouble rewriting a DICOM file with metadata: converting table to structure
조회 수: 1 (최근 30일)
이전 댓글 표시
Currently, I have my metadata (from a different source) as follows:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/291970/image.png)
Is there any way to convert a 216x2 table into a structure that is 1x1 but with 216 fields of 216 values? something more like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/291971/image.png)
I have also attached the original metadata table (with some fields removed) as a reference.
댓글 수: 0
답변 (1개)
Athul Prakash
2020년 5월 13일
Hi Johnathan,
Your issue may be solved this way:
% If 'T' is the variable holding the table,
C = table2cell(T);
C = C';
C = C(:);
S = struct(C{:})
It's farily interesting what's going in here, unde the hood.
We're trying to create a struct using the syntax: struct(field1, value1, field2, value2, ..., fieldN, valueN). So we need to be passing all 216*2=432 fields in this way.
To start with, we convert the table 'T' into a cell array which is easier to manipulate.
Then we linearize this 216x2 cell array into a one dimensional cell array. (We need to transpose the Cell Array first, to linearize in the right order)
Finally, we make use the fact that a cell array when indexed using {} in a range, would produce a comma-separated list which can be passed into functions where each element acts like a different function argument.
Hope it helps!
참고 항목
카테고리
Help Center 및 File Exchange에서 DICOM Format에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!