MATLAB Answers

4D matrix in .txt and .csv

48 ビュー (過去 30 日間)
Mar
Mar 2018 年 11 月 16 日
コメント済み: Lin 2021 年 1 月 13 日 2:58
I have 4D data which are 3D images + time. Data = [256,256,22,99]. I would like to save it in text file and .csv. How can I do this?

  1 件のコメント

Lin
Lin 2021 年 1 月 13 日 2:58
Is there any update answer for this question?

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

回答 (1 件)

Miriam
Miriam 2018 年 11 月 16 日
編集済み: Miriam 2018 年 11 月 16 日
You could reshape your data (https://www.mathworks.com/help/matlab/ref/reshape.html) into a 2D matrix (something like [256x256x22,99]). If you want you could also save the 3 xyz coordinates (i.e. indices) in the matrix (size [256x256x22,3+99]).
To save as .txt, try dlmwrite (https://www.mathworks.com/help/matlab/ref/dlmwrite.html)
To save as .csv, try csvwrite (https://www.mathworks.com/help/matlab/ref/csvwrite.html)

  3 件のコメント

Mar
Mar 2018 年 11 月 16 日
Why should I reshape my data? Are already 4D.
Miriam
Miriam 2018 年 11 月 16 日
dlmwrite() and csvwrite() will reshape your data into a 2D matrix anyway; if you reshape it yourself you'll have more control over the final format. To my knowledge there is no way to save a 4D dataset in .txt or .csv. You could save it as a 4D .mat variable using save().
Valeriy
Valeriy 2018 年 11 月 25 日
Thanks Miriam for your answer. Did I understand right, that if I have 4D matrix, 3 dimensions of which are space coordinates (x,y,z) and in each voxel I have some value, intensity of something, for example, so as you told:
>If you want you could also save the 3 xyz coordinates (i.e. indices) in the matrix (size [256x256x22,3+99]).
Is it correct? Could you precise, how it is possible to realize?

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

Community Treasure Hunt

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

Start Hunting!

Translated by