XML file generation in matlab
显示 更早的评论
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
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
2020-3-5
编辑:Permvir Singh
2020-3-5
Permvir Singh
2020-3-5
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
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
2020-3-5
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Code Interface Definitions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!