When you write a DICOM file, you need to set a number of entries in the data dictionary, including SOPClassUID (but several others as well!)
dicomwrite(data2,'NEWDATA.dcm','CreateMode', 'copy');
CreateMode 'copy' is really only useful if you are passing in meta_struct or info
Creating a DICOM file "from scratch" is a bit of a nuisance, all of the fields that need to be set.
It is usually easier to start with a representative file and copy the headers out of that file, such as
representative_fname = 'nemay_representative.dcm';
representative_info = dicominfo(representative_fname);
dicomwrite(data2,'NEWDATA.dcm', representative_info, 'CreateMode', 'copy');