MATLAB variable to 3D slicer

I am a new learner. I have processed the 3D PET image variable in .mat format and I want to download it as a volume in the 3D slicer for registration with CT. How to do that while keeping the same voxel size of 3D PET? Thanks

You can use a standard 3D image file format that stores the image geometry (origin, spacing, axis directions). You can use this nrrd writer: SlicerMatlabBridge/nrrdwrite.m at master · PerkLab/SlicerMatlabBridge · GitHub

Thank you for that, but I tried to convert them into .dcm by the below code. However, when loading the processed PET image ‘convolvedPET’, 3D slicer shows the scalar range (14.65 to 4.761x 10^7) in Matlab for convolvedPET.mat has range (4.3x10^-5 tp 684). Please let me the problem or may be I am not aware of something.
Here is the code,

 %% Section 1 PET original image in DICOM
folderPath = 'PET';
filePattern = fullfile(folderPath, 'IMG-0001-*.dcm');
dcmFiles = dir(filePattern);
numSlices = numel(dcmFiles);
PET = zeros(256, 256, numSlices);
metadataArray = cell(numSlices, 1); % Array to store metadata
for i = 1:numSlices
    fileName = fullfile(folderPath, dcmFiles(i).name);
    info = dicominfo(fileName);
    PET(:, :, i) = dicomread(info);
    metadataArray{i} = info; % Save metadata in the array
 **PET was resized and convolved to get a processed PET image named  'convolvedPET'** 
%% write dicom files and save in a folder 
outputFolderPath = 'Processed_PET';
if ~isfolder(outputFolderPath)
% dicom write 
for i = 1:numSlices
    % Retrieve the processed data for the current slice
    processedData = convolvedPET(:, :, i);
    % Retrieve the metadata for the current slice
  originalMetadata = metadataArray{i};
    % Update the rows and columns in the metadata
    originalMetadata.Rows = size(processedData, 1);
   originalMetadata.Columns = size(processedData, 2);
    % Update the pixel spacing in the metadata (assuming the new spacing is 3.0 mm)
   originalMetadata.PixelSpacing = [3.0, 3.0];
    % Save the processed data with the updated metadata
    outputFileName = fullfile(outputFolderPath, ['processed_', dcmFiles(i).name]);
    dicomwrite(processedData, outputFileName, originalMetadata,'CreateMode','copy');

Thank you. I used that, but when I get the image in the 3D slicer its orientation changes. Please advise on dealing with this

In files, the world coordinate system is LPS; while internally in Slicer the world coordinate system is RAS. However, this should not cause any problems, as Slicer converts everything from LPS to RAS coordinate system (images, models, transforms, etc.) when reading data from file.