How to convert 3D .nii to .mat vector?

7 ビュー (過去 30 日間)
Wasna Madushanka Ediri Arachchi
Wasna Madushanka Ediri Arachchi 2017 年 12 月 7 日
回答済み: Anudeep Kumar 2025 年 3 月 11 日
I want to convert 3D matrix data of .nii to single array .mat file? Can you anyone provide the code pls?

回答 (1 件)

Anudeep Kumar
Anudeep Kumar 2025 年 3 月 11 日
Hey Wasna,
The niftiread() function can help you do that very easily.
The niftiread(your_file), function reads and returns the volumetric data of your file in the specified variable which you can modify according to your needs.
Below is a code snippet for your requirement.
% Specify the path to your NIfTI file
niiFilePath = 'path_to_your_file.nii';
% Read the NIfTI file
niiData = niftiread(niiFilePath);
% Convert the 3D matrix to a single array
% This step converts the shape of data to a single array
singleArray = niiData(:);
% Specify the path for the .mat file
matFilePath = 'output_file.mat';
% Save the data to a .mat file
save(matFilePath, 'singleArray');
Here is a link to the documentation for niftiread():
I hope that helped!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by