MATLAB: Convert .MAT to .DAT in matlab for a 2D Image

MATLAB

Hi,
I've been trying to convert .Mat files to .Dat file in MATLAB. Actually the codes takes .Dat file of an image and then denoises it.
I have .MAT MRI images and I'm unable to convert it into .DAT
Is there any way of changing the code if the first option isn't feasible?
Thanks for the response x

Best Answer

matname = [dataset '.mat'];
datastruct = load(matname);
fn = fieldnames(datastruct);
outname = [dataset '.dat'];
data_to_save = datastruct.(fn{1});
save(outname, 'data_to_save', '-ASCII');