how to convert a structure format to xml?

42 visualizaciones (últimos 30 días)
Parham Babakhani Dehkordi
Parham Babakhani Dehkordi el 21 de Jun. de 2018
Respondida: Anas Alakhras el 24 de Feb. de 2023
Hi, I am trying to convert my file named as 's' with struct format to xml format. I was able to find the code written below. I saved my file as 's.struct' together with the code in one folder. Then, in the command line I write 'file=struct2xml(s)' in which 's' is the file with format struct and 'file' is the one that must be saved as xml format. but it says: Undefined function or variable 's'. I attached the error code. The code is:
EDIT: Copyright code removed. Can be found here:
  3 comentarios
Parham Babakhani Dehkordi
Parham Babakhani Dehkordi el 21 de Jun. de 2018
My file name (that needs to be converted to xml) is called 's'. I the first line of the code I have: 'function varargout = struct2xml( s, varargin )' How should I call my file to this function?
Stephen23
Stephen23 el 21 de Jun. de 2018
Editada: Stephen23 el 21 de Jun. de 2018
@Parham Babakhani Dehkordi: the name of some file is irrelevant to this error: note that the error message does not mention files anywhere. You do NOT have a variable named s in the workspace, which is what the error message clearly states.
"Hi, I am trying to convert my file named as 's' with struct format to xml format"
What is a "struct" file format? I have never heard of this. You do not import the file, or explain the file format and how this relates to a MATLAB structure (which is required as an input to struct2xml).

Iniciar sesión para comentar.

Respuestas (3)

Pierre Harouimi
Pierre Harouimi el 24 de Feb. de 2022
Please use the writestruct function.

KSSV
KSSV el 21 de Jun. de 2018
  6 comentarios
Parham Babakhani Dehkordi
Parham Babakhani Dehkordi el 21 de Jun. de 2018
The problem is not so complicated. Within the code there is a variable 's': function varargout = struct2xml( s, varargin ) I have one dataset (which are mainly groundtruth, they are pictures in one file), the name of the file can be everything, let call it 12345.struct I donot know how to relate this file in the same directory as the matlab code to the input variable s in the code.
Stephen23
Stephen23 el 21 de Jun. de 2018
Editada: Stephen23 el 21 de Jun. de 2018
"The problem is not so complicated"
I agree.
"I donot know how to relate this file in the same directory as the matlab code to the input variable s in the code"
If you want to use the contents of that file in the function struct2xml then you will need to import the file contents into MATLAB (and more particularly into a structure variable):
You appear to think that struct2xml has something to do with your .struct file, whereas in fact it doesn't. The struct2xml description states very clearly "Convert a MATLAB structure into a XML file." Your file, regardless of its file extension, is not a MATLAB structure.
"Because I have the same problem as Raúl did on the link that you gave me and nobody answered it"
No, you have a totally different problem. Raúl states that "However, non xml file is created", which indicates that Raúl provided the function with a structure as its first argument but got an unexpected output file. You have not provided any input argument, and the error is related to that - these are two totally different problems.
"Within the code there is a variable 's'..."
Indeed there is. But your input argument (which so far you have not defined) does not need to have the same name. The names used inside a function are irrelevant to the names of the input and output arguments that that function is called with.

Iniciar sesión para comentar.


Anas Alakhras
Anas Alakhras el 24 de Feb. de 2023
Convert a MATLAB structure into a xml file
[ ] = struct2xml( s, file )
xml = struct2xml( s )

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by