How to I convert a 3D array into 4-column table (x y z value)?

1 回表示 (過去 30 日間)
Johnathan Zeng
Johnathan Zeng 2020 年 1 月 9 日
コメント済み: Johnathan Zeng 2020 年 1 月 10 日
For example, I have the following (reading slices of DICOM images):
for ii = 1:length(files)
% get fileName
fileName = strcat(myPath, files(ii).name);
metaData{ii} = dicominfo(fileName);
sliceNum = metaData{ii}.SOPInstanceUID(end-2:end);
imgData(:,:,ii) = dicomread(fileName);
writematrix(imgData(:,:,ii), strcat(myPath, exportName, '-', sliceNum, '.csv'))
end
The format is as follows: imgData(x,y,z) = value
Where imgData is a 3D array of values such that imgData(:,:,z) will give me a 512x512 array of values.
If imgData(1,2,3) = 4, I want a 2D array to have the following:
x y z value
1 2 3 4
What is the best way to convert the index of the data into a column?

採用された回答

Matt J
Matt J 2020 年 1 月 9 日
編集済み: Matt J 2020 年 1 月 9 日
[m,n,p]=size(imgData);
[x,y,z]=ndgrid(1:m,1:n,1:p);
out=[x(:),y(:),z(:),imgData(:)];
  1 件のコメント
Johnathan Zeng
Johnathan Zeng 2020 年 1 月 10 日
That worked out perfectly! Thank you!

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

その他の回答 (0 件)

カテゴリ

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