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

조회 수: 6 (최근 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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by