need 'for loop' to check 1:32 bit

3 次查看(过去 30 天)
I have 606,774(1 row means event no.1) event number in 8 column(these are 32 bit values), these numbers are in decimal as shown in below. a=(strVals(1:10,1:8))
a =
0 0 0 0 0 3 0 0
0 0 0 0 0 576 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 48
0 0 1536 8192 0 0 0 0
0 0 0 0 0 0 50331648 0
0 0 0 0 0 6291456 0 0
0 0 0 67108864 0 0 256 0
0 0 0 768 0 0 0 0
0 0 0 4194304 0 0 0 0
This is only for 1:10 event,(I have 606,774 event no.). What I want here is, how to convert these number into binary at same time and how can I check 1:32 bit at once. I have use "bitget" function but I only able to get separately, may I need 'for loop' to get at once?1:32 bit means 1 through 32 bit of binary number(convert above decimal numbers into binary), so I need to know how to write a "for loop" to check each bit one at a time. Like >> bitget(a,1) command checks if the first (smallest/lowest) bit is set for all these numbers at the same time.
Please help me, thanks in advance.
  4 个评论
Geoff Hayes
Geoff Hayes 2014-5-30
Why do you need to check all 32 bits for all 606,774 events? What are you looking for in particular?
Chiranjibi
Chiranjibi 2014-5-30
Actually this is for data analysis in nuclear detector. These above 8 columns are the stretcher value from stretcher 0-7.Each event are related to channel so, I'm looking which channel were hit(means 1). For this we need to convert above number to binary first(up to 32 bit)like for first row dec2bin(3) gives binary number - 00000000000000000000000000000011 that means channel 1&2 were hit and so on. it is not possible to count the bit one by one for 606,774 events. So how to write "for loop" to check each bit one at a time, from this we can identify which bit get 1/0. I hope you understand my question, thanks.

请先登录,再进行评论。

采纳的回答

Geoff Hayes
Geoff Hayes 2014-5-30
Since you are looking for which channels were hit across all stretchers for all events, then you will need two for loops for the looping of the data, and an additional inner for loop to iterate over the 32 channels. Something like
[m,n] = size(a);
for event=1:m
for stretcher=1:n
% do stuff
end
end
If you are only interested in those stretchers from some event that has a hit channel, then you can exclude all the 0's (since no hits on any channel) and the "do stuff" from above becomes
val = a(event,stretcher);
if val~=0
% now loop over the 32 channels
bitMask = 1;
channelsHit = cast(zeros(1,32),'uint8');
atHit = 0;
% iterate over each channel
for k=1:32
if bitand(val,bitMask)
% is one so a hit on channel k!
atHit = atHit+1;
channelsHit(atHit) = k;
end
% bit shift the mask by one
bitMask=bitshift(bitMask,1);
end
% remove empty elements from array and so we have a variable sized
% array of hit channels for the (event, stretcher) pair
channelsHit = channelsHit(1:atHit);
end
Once you have your list of hit channels for the (event, stretcher) pair, you can save those three pieces of information to a cell array for later analysis.
  14 个评论
Chiranjibi
Chiranjibi 2014-6-9
编辑:Chiranjibi 2014-6-9
Thanks, I got 6 row and 6 column array from this code, and now I need to write function for this file to check broken channel. Like
strVals=readLBCF_File('/data/chocula/lbcfdata/data/ne/raw/VData0101_140101001844',0, 0);
................
for ii=1:32
results(ii,:)=sum( bitand(a, 2^(ii-1) ) > 0 );
end
[R,C] =find(results==0);
for ii=1:32
disp(['stretcher:' num2str(C(ii)) ', channel:' num2str(R(ii)) ' appear to be dead.'])
end
Can you please help me to write function in 2nd line(dot line).
Geoff Hayes
Geoff Hayes 2014-6-10
Chiranjibi - The code you pasted above will not always work
[R,C] =find(results==0);
for ii=1:32
disp(['stretcher:' num2str(C(ii)) ', channel:' num2str(R(ii)) ' appear to
be dead.'])
end
There is no guarantee that the number of elements in R or C will be 32. That should have been obvious from the results matrix that you posted in a previous comment.
As well, again in your above comment, there is a dotted line that you are asking help to "fill in" without providing any details or making the attempt yourself. Attempting something, on your own, is important and necessary.
Good luck with your coding of this interesting problem!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by