title: How do I save nii files into one nii file using MATLAB
body: <p>I have 360 3D-nifti files, I want to read all these files and save into one nifti file using <a href="https://au.mathworks.com/matlabcentral/fileexchange/8797-tools-for-nifti-and-analyze-image" rel="nofollow noreferrer">Nifti Analyze tool</a> that should yield a 4D file of large size. So far I have written following lines  </p>
  
  <pre><code>clear all;
  clc; 
  
  fileFolder=fullfile(pwd, '\functional');
  files=dir(fullfile(fileFolder, '*.nii'));
  fileNames={files.name};
  
       for i=1:length(fileNames)
  
            fname=fullfile(fileFolder,fileNames{i});
            z(i)=load_nii(fname);
            y=z(i).img;
            temp(:,:,:,i) = make_nii(y);
            save_nii(temp(:,:,:,i), 'myfile.nii')
  
  fprintf('Iter:  %d\n', i)
  end
  </code></pre>
  
  <p>This code facilitates with a variable temp that is 4D struct and contains all the images. However, myfile.nii is just one single file its not all the images because its size is just 6mb it should be atleast one 1gb.
  Can someone please have a look and let me know where I am wrong?</p>