I am trying to generate xml file dynamically. I am having an issue in printing the desired values.
RB_Array = 2147483647 0 0 0 0 0 0 0 0 C =DFFE0000
RB_Array = 2147483647 1 0 0 0 0 0 0 0 C =00000001
I have generated these two RB_Array with two associated using bitwise operation in matlab, and hexadecimal values stored in C.
if RB_Array(1,1)==0
rb_node.setTextContent('00000000');
else
rb_node.setTextContent(num2str(C));
end
I am having an output as <rb-assign block="0-31">00000001</rb-assign>. Instead of 00000001, I want to print DFFE0000. How can I do that?

7 件のコメント

Guillaume
Guillaume 2020 年 3 月 5 日
First of all, it's not clear what's the type and content of your array. Can you please use valid matlab syntax to express the content of your array. It can't be a numeric array since C =DFFE0000 is not valid content
>> RB_Array = [2147483647 0 0 0 0 0 0 0 0 C =DFFE0000] %attempt at interpreting your example
RB_Array = [2147483647 0 0 0 0 0 0 0 0 C =DFFE0000]
Error: Incorrect use of '=' operator. To assign a
value to a variable, use '='. To compare values
for equality, use '=='.
Maybe it's a cell array
RB_Array = {2147483647 0 0 0 0 0 0 0 0, 'C =DFFE0000'} %maybe
but num2str wouldn't work on that.
So what is it? and what is C in your above code.
Permvir Singh
Permvir Singh 2020 年 3 月 5 日
編集済み: Permvir Singh 2020 年 3 月 5 日
I am working on a very complex issue. I have written a generic code which fetches the data from the workspace, and instantly generates XML file for UEs(User Equipment) which can go up to infinity(No upper limit) for 5G tecnology. For test case I fetched RB(Resource Block) of a UE. When I fetched it from workspace
rb2 = 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
I then performed bitwise operation to convert it into the desired hexadecimal form which is acceptable to our equipment by iterating from 17 to 32.
a = [0 0 0 0 0 0 0 0 0]; RB_Array = (int32(a)); cntr1=length(rb2)
for rb = 1:cntr1
x = floor(rb2(rb)/32);
y = mod(rb2(rb),32);
z= bitshift(1,(y));
A =RB_Array(x+1);
B = bitor(double(A),z);
RB_Array(x+1) = B
C = dec2hex(B,8)
end
For each iteration of rb(from 17 to 32), RB_Array gets updated, and generates the hexadecimal value. The last RB_Array is to be used in XML file.
rb= 31
RB_Array = 2147483647 0 0 0 0 0 0 0 0
C =DFFE0000 (The value to be printed in XML file)
rb =32
RB_Array = 2147483647 1 0 0 0 0 0 0 0
C =00000001(The value to be printed in XML file)
From rb 31 to 32, the first value remains the same, and in rb=32, the second value is updated to 1. This means that C=DFFE0000 corresponds to 2147483647, and C=00000001 corresponds to 1.
if RB_Array(1,1)==0
rb_node.setTextContent('00000000');
else
rb_node.setTextContent(num2str(C));
end
The result is
<rb-assign block="0-31">00000001</rb-assign>
<rb-assign block="32-63">00000001</rb-assign>
<rb-assign block="64-95">00000000</rb-assign>
<rb-assign block="96-127">00000000</rb-assign>
<rb-assign block="128-159">00000000</rb-assign>
<rb-assign block="160-191">00000000</rb-assign>
<rb-assign block="192-223">00000000</rb-assign>
<rb-assign block="224-255">00000000</rb-assign>
<rb-assign block="256-287">00000000</rb-assign>
However it should be <rb-assign block="0-31">DFFE0000</rb-assign> for block 0-31. Rest is fine The elements of RB_Array correspond to the blocks(bit size) 0-31 t0 256-287.
Thanks
Permvir Singh
Permvir Singh 2020 年 3 月 5 日
Hard coding can not be done.
Guillaume
Guillaume 2020 年 3 月 5 日
First of all, shouldn't RB_Array be of type uint32 instead of int32. With your current code, whenever mod(rb2(rb), 32) is equal to 31 this will cause an overflow of int32 which will set all bits of the corresponding element of RB_Array to 1. Try your code with e.g
rb2 = [31, 63, 95, 127];
%The following is your code unchanged
a = [0 0 0 0 0 0 0 0 0]; RB_Array = (int32(a)); cntr1=length(rb2);
for rb = 1:cntr1
x = floor(rb2(rb)/32);
y = mod(rb2(rb),32);
z= bitshift(1,(y));
A =RB_Array(x+1);
B = bitor(double(A),z);
RB_Array(x+1) = B;
C = dec2hex(B,8);
end
%see the result
dec2bin(RB_array)
If I understood your code correctly, it's a very convoluted way of setting the bits of RB_array.
As for your code that writes to the xml it's unclear where it's located, why you test just RB_Array(1) and what it's trying to do. Note that if C is the same C as in the above code, then num2str is a complete waste of time. C is already string.
Permvir Singh
Permvir Singh 2020 年 3 月 5 日
編集済み: Guillaume 2020 年 3 月 5 日
Thank you very much for your time to help me. Here is the complete code. I have hard coded for test purpose for one UE only, and with limited information The RB_Array is the array of 9 elements which correspond to the different blocks ranging from 0-31,32-63,64-95,96-127 to 256-287. These blocks are fixed, and can not be changed. As we iterate through the RBs, RB_Array should be updated, and corresponding value of hexadecimal number(C) shound be generated. The last RB_Array is the updated array. The next task is assign the corresponding hexadecimal values to the different resource blocks i,e 0-31 to 256-287 based on the updated RB_Array. If any element of the RB_Array is 0, then '00000000' should be printed in xml file corresponding to that block, otherwise it should print the corresponding hexadecimal value. In this example, the first two elements are not zero, therefore hexadecimal values should be printed. The other elements are zeros, so 00000000 should be printed. That is the whole idea of project.
docNode = com.mathworks.xml.XMLUtils.createDocument('scenario');
scenario = docNode.getDocumentElement;
cell_node = docNode.createElement('cells');
docNode.getDocumentElement.appendChild(cell_node);
slot_node = docNode.createElement('slot');
docNode.getDocumentElement.appendChild(slot_node);
slot_node.setAttribute('number','1');
cell_node.appendChild(slot_node);
ue_node = docNode.createElement('ue');
docNode.getDocumentElement.appendChild(ue_node);
ue_node.setAttribute('id','1');
slot_node.appendChild(ue_node);
dl_node = docNode.createElement('dl-dci');
docNode.getDocumentElement.appendChild(dl_node);
dl_node.setAttribute('format', '1-1');
ue_node.appendChild(dl_node);
a = [0 0 0 0 0 0 0 0 0];
RB_Array = (uint32(a));
rb2 = [17 18 19 20 21 22 23 24 25 26 27 28 28 30 31 32];
cntr1=length(rb2)
for rb = 1:cntr1
x = floor(rb2(rb)/32);
y = mod(rb2(rb),32);
z= bitshift(1,(y));
A =RB_Array(x+1);
B = bitor(double(A),z);
RB_Array(x+1) = B
C = dec2hex(B,8)
end
rb_node = docNode.createElement('rb-assign');
rb_node.setAttribute('block', '0-31');
docNode.getDocumentElement.appendChild(rb_node);
if RB_Array(1,1)==0
rb_node.setTextContent('00000000');
else
rb_node.setTextContent(C);
end
rb_node1 = docNode.createElement('rb-assign');
rb_node1.setAttribute('block', '32-63');
docNode.getDocumentElement.appendChild(rb_node1);
if RB_Array(1,2)==0
rb_node1.setTextContent('00000000');
else
rb_node1.setTextContent(C);
end
rb_node2 = docNode.createElement('rb-assign');
rb_node2.setAttribute('block', '64-95');
docNode.getDocumentElement.appendChild(rb_node2);
if RB_Array(1,3)==0
rb_node2.setTextContent('00000000');
else
rb_node2.setTextContent(C);
end
rb_node3 = docNode.createElement('rb-assign');
rb_node3.setAttribute('block', '96-127');
docNode.getDocumentElement.appendChild(rb_node3);
if RB_Array(1,4)==0
rb_node3.setTextContent('00000000');
else
rb_node3.setTextContent(C);
end
rb_node4 = docNode.createElement('rb-assign');
rb_node4.setAttribute('block', '128-159');
docNode.getDocumentElement.appendChild(rb_node4);
if RB_Array(1,5)==0
rb_node4.setTextContent('00000000');
else
rb_node4.setTextContent(C);
end
rb_node5 = docNode.createElement('rb-assign');
rb_node5.setAttribute('block', '160-191');
docNode.getDocumentElement.appendChild(rb_node5);
if RB_Array(1,6)==0
rb_node5.setTextContent('00000000');
else
rb_node5.setTextContent(C);
end
rb_node6 = docNode.createElement('rb-assign');
rb_node6.setAttribute('block', '192-223');
docNode.getDocumentElement.appendChild(rb_node6);
if RB_Array(1,7)==0
rb_node6.setTextContent('00000000');
else
rb_node6.setTextContent(C);
end
rb_node7 = docNode.createElement('rb-assign');
rb_node7.setAttribute('block', '224-255');
docNode.getDocumentElement.appendChild(rb_node7);
if RB_Array(1,8)==0
rb_node7.setTextContent('00000000');
else
rb_node7.setTextContent(C);
end
rb_node8 = docNode.createElement('rb-assign');
rb_node8.setAttribute('block', '256-287');
docNode.getDocumentElement.appendChild(rb_node8);
if RB_Array(1,9)==0
rb_node8.setTextContent('00000000');
else
rb_node8.setTextContent(C);
end
dl_node.appendChild(rb_node);
dl_node.appendChild(rb_node1);
dl_node.appendChild(rb_node2);
dl_node.appendChild(rb_node3);
dl_node.appendChild(rb_node4);
dl_node.appendChild(rb_node5);
dl_node.appendChild(rb_node6);
dl_node.appendChild(rb_node7);
dl_node.appendChild(rb_node8);
xmlwrite('infoTMA.xml',docNode);
type('infoTMA.xml');
Result obtained:
<rb-assign block="0-31">00000001</rb-assign> here DFFE0000 is desired
<rb-assign block="32-63">00000001</rb-assign>
<rb-assign block="64-95">00000000</rb-assign>
<rb-assign block="96-127">00000000</rb-assign>
<rb-assign block="128-159">00000000</rb-assign>
<rb-assign block="160-191">00000000</rb-assign>
<rb-assign block="192-223">00000000</rb-assign>
<rb-assign block="224-255">00000000</rb-assign>
<rb-assign block="256-287">00000000</rb-assign>
Guillaume
Guillaume 2020 年 3 月 5 日
編集済み: Guillaume 2020 年 3 月 5 日
"The RB_Array is the array of 9 elements [...] These blocks are fixed, and can not be changed. [...]"
Yes, I understood that and I understand that it is preset. What I was saying is that you probably have an error in your construction of the RB_Array because you've declared it as int32 instead of uint32. I've given you an example that easily demonstrates the problem using your code. If you try your code with input
rb2 = [31, 63, 95, 127];
You'll get as output:
>> dec2hex(RB_Array)
ans =
9×8 char array
'7FFFFFFF'
'7FFFFFFF'
'7FFFFFFF'
'7FFFFFFF'
'00000000'
'00000000'
'00000000'
'00000000'
'00000000'
whereas it should be
>> dec2hex(accumarray(floor(rb2(:)/32)+1, mod(rb2(:), 32), [9, 1], @(v) sum(2.^unique(v))))
ans =
9×8 char array
'80000000'
'80000000'
'80000000'
'80000000'
'00000000'
'00000000'
'00000000'
'00000000'
'00000000'
edit: I see you've fixed the bug in your new comment. Still as you can see above, the calculation can be done in just one line.
Permvir Singh
Permvir Singh 2020 年 3 月 5 日
Thank you very much for the support. Lots of appreciation.

サインインしてコメントする。

 採用された回答

Guillaume
Guillaume 2020 年 3 月 5 日

0 投票

First, whenever you copy/paste code multiple times and only change an index each time you need to realise that you need to replace that with a loop.
Secondly, I don't understand why you discriminate between RB_Array(i) being equal to 0 or not. In either case, dec2hex(RB_Array(i), 8) is what you want to output.
I've not tried to understand the bug in your code, the following will do what you want in a lot less lines:
%this part unchanged
docNode = com.mathworks.xml.XMLUtils.createDocument('scenario');
scenario = docNode.getDocumentElement;
cell_node = docNode.createElement('cells');
docNode.getDocumentElement.appendChild(cell_node);
slot_node = docNode.createElement('slot');
docNode.getDocumentElement.appendChild(slot_node);
slot_node.setAttribute('number','1');
cell_node.appendChild(slot_node);
ue_node = docNode.createElement('ue');
docNode.getDocumentElement.appendChild(ue_node);
ue_node.setAttribute('id','1');
slot_node.appendChild(ue_node);
dl_node = docNode.createElement('dl-dci');
docNode.getDocumentElement.appendChild(dl_node);
dl_node.setAttribute('format', '1-1');
ue_node.appendChild(dl_node);
%your rb2 input
rb2 = [17 18 19 20 21 22 23 24 25 26 27 28 28 30 31 32];
%calculation of RB_Array and creation of xml elements
RB_Array = uint32(accumarray(floor(rb2(:)/32)+1, mod(rb2(:), 32), [9, 1], @(v) sum(2.^unique(v))));
for row = 1:numel(RB_Array)
rb_node = docNode.createElement('rb-assign');
rb_node.setAttribute('block', sprintf('%d-%d', (row-1)*32, row*32-1));
docNode.getDocumentElement.appendChild(rb_node);
rb_node.setTextContent(dec2hex(RB_Array(row), 8));
dl_node.appendChild(rb_node);
end

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by