How to Convert .mat to xml?

30 views (last 30 days)
Disha
Disha on 4 Feb 2023
Answered: Jasvin on 10 Feb 2023
I have a .mat file, and I tried to use the foolowing to convert it to a .xml file.
>> [fname1,fpath1] = uigetfile('*.mat');
if fpath1==0, error('no file selected'); end
[num,txt,raw] = read( fullfile(fpath1,fname1) );
The error message is as follows
Incorrect number or types of inputs or outputs for function 'read'.
I know the problem is using the read function for .mat. Can anyone tell me what to use so that I can save the file further on in xml using the save function?
Thank you.
  1 Comment
Rik
Rik on 4 Feb 2023
Why do you want to use the save function to write xml files, and why aren't you using load to read your mat file?

Sign in to comment.

Answers (1)

Jasvin
Jasvin on 10 Feb 2023
The read() function has several uses which include reading data from a datastore (https://www.mathworks.com/help/matlab/ref/matlab.io.datastore.read.html?s_tid=doc_ta) but it’s not used to read .mat files. For that you can use the load() function directly as:
load(fullfile(fpath1, fname1));
For more information regarding the load function refer to the below link:
This will get the variables you want in the base workspace. But to convert the .mat file to XML you can directly use the mat2xml function of the XML4MAT module on FileExchange. You can refer to the link below: https://www.mathworks.com/matlabcentral/fileexchange/6268-xml4mat-v2-0?s_tid=srchtitle_convert%2520mat%2520to%2520xml_2

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!