How to Convert .mat to xml?

64 vues (au cours des 30 derniers jours)
Disha
Disha le 4 Fév 2023
Réponse apportée : Jasvin le 10 Fév 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 commentaire
Rik
Rik le 4 Fév 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?

Connectez-vous pour commenter.

Réponses (1)

Jasvin
Jasvin le 10 Fév 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

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by