how to convert a structure format to xml?
Ältere Kommentare anzeigen
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 Kommentare
Adam
am 21 Jun. 2018
Where do you get 'undefined function or variable 's''> Is it inside this function or when you call it? Do you have a variable called 's' on your command line?
Parham Babakhani Dehkordi
am 21 Jun. 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).
Antworten (3)
Pierre Harouimi
am 24 Feb. 2022
2 Stimmen
KSSV
am 21 Jun. 2018
0 Stimmen
See this file exchange function: https://in.mathworks.com/matlabcentral/fileexchange/28639-struct2xml
6 Kommentare
Parham Babakhani Dehkordi
am 21 Jun. 2018
KSSV
am 21 Jun. 2018
Why?
Parham Babakhani Dehkordi
am 21 Jun. 2018
@Parham Babakhani Dehkordi: Read the error message
Undefined function or variable 's'
The error messages in the screenshot shows that you don't have any variable named s is the workspace, so there is no point in trying to call the function like this:
struct2xml(s)
or using any of those other (some of them buggy) syntaxes, because you have not defined any variable s in that workspace, that you can use an input to the function.
The fact that you happen to have a file named s.struct in some folder is totally irrelevant.
If you want to use that function then you will need to provide it with the inputs that it requires in the formats specified by its clearly written help. Its help states that its first input s must be a structure array. Your screenshot shows that you do not have a structure array in the workspace, so your attempts to call it are all going to throw errors: this has nothing to do with struct2xml, but is solely caused by the fact that you don't have a structure in your workspace.
If you have not defined what s is beforehand, then there is nothing that MATLAB can do.
How to define variables and call functions is explained in the introductory tutorials, which are recommended for all beginners:
Parham Babakhani Dehkordi
am 21 Jun. 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.
Anas Alakhras
am 24 Feb. 2023
0 Stimmen
Convert a MATLAB structure into a xml file
[ ] = struct2xml( s, file )
xml = struct2xml( s )
Kategorien
Mehr zu Structured Data and XML Documents finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!