Subscript indices must either be real positive integers or logicals error when using getFirstChild.getData function
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
sermet
am 11 Mär. 2017
Beantwortet: Geoff Hayes
am 11 Mär. 2017
I have a xml file (I attached the file). I can retrieve related variables in xml file but when it comes to store them with using loop, I got error. I tried to store variable as follows;
docNode = xmlread('2017-03-03.xml');
l = docNode.getElementsByTagName('aSqRoot');
char(l.item(0).getFirstChild.getData); %first aSqRoot value
for i = 0:(l.getLength - 1)
x(i)=char(l.item(i).getFirstChild.getData); % all aSqRoot in almanac file
end
How can I store the below variable?
char(l.item(i).getFirstChild.getData)
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 11 Mär. 2017
sermet - the error message is telling you that you are trying to access an element in an array with an index that is invalid. Indices must be integers and positive (greater than zero). Try changing your code from
for i = 0:(l.getLength - 1)
to
for i = 1:l.getLength
so that we avoid the zero index (unlike other languages like C++ where we would use a zero index).
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!