Hi everyone! Please I need some help with batch importing a bunch of xml file files I have in a folder into my workspace. I tried to use xml2struct but it only gets one

1 visualización (últimos 30 días)
clear all
clc
[file_list,path_name]=uigetfile('.xml', 'Grab the files you want to process', 'Multiselect', 'on' );
%%
for i=1:length(file_list)
filename=file_list(i);
data=xml2struct('filename')
end
% Using the xml2struct with a path to each xml file works but my problem is
% how to loop through each file in the folder

Respuesta aceptada

Simon Chan
Simon Chan el 15 de Jul. de 2021
Editada: Simon Chan el 15 de Jul. de 2021
Try to add the indexing for variable 'data' and each file name
for i=1:length(file_list)
data(i)=xml2struct(file_list{i})
end
  2 comentarios
Daniel Abraham
Daniel Abraham el 15 de Jul. de 2021
Hi Simon, thanks for your reply, but it gives the error unfortunately.
Error using xml2struct (line 48)
The file filename.xml could not be found
Error in test (line 7)
data(i)=xml2struct('filename')
48 error(['The file ' file ' could not be found']);
:(
I believe the issue is that the function works with a directory to the file but not with the string 'filename', but it is just one file name and that can't be iterated or maybe I'm missing something
Simon Chan
Simon Chan el 15 de Jul. de 2021
Modify again to take care of the file name:
for i=1:length(file_list)
data(i)=xml2struct(file_list{i});
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by