How to convert 3D .nii to .mat vector?
조회 수: 6 (최근 30일)
이전 댓글 표시
I want to convert 3D matrix data of .nii to single array .mat file? Can you anyone provide the code pls?
댓글 수: 0
답변 (1개)
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!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!