I do know one solution but it would be rather ugly
if numel(size(DATA))==2
[grad_vec(:,1),grad_vec(:,2)] = gradient(DATA);
elseif numel(size(DATA))==3
[grad_vec(:,:,:,1),grad_vec(:,:,:,2),grad_vec(:,:,:,3)] = gradient(DATA);
elseif numel(size(DATA))==4
[grad_vec(:,:,:,:,1),grad_vec(:,:,:,:,2),grad_vec(:,:,:,:,3),grad_vec(:,:,:,:,4)] = gradient(DATA);
.
.
.
end
Then I know that my data will have no more than say 10 dimensions so I just continue this elseif to the 10th case