# Finding bit's postions in cell

1 view (last 30 days)
Edited: Adam Danz on 18 Oct 2019
I have a binary number in a cell. I want to find 1's bit positon in cell. Can anyone help me out here.
val =
'0000000000000000'
'0000000000000010'
'0000000000000011'
'0000000000000111'
'0000000000001000'
'0000000000011010'
'0000000000100000'
'0000000000100001'
'0000000000100010'
'0000000000110100'
'0000000001001100'
'0000000001010101'
'0000000001011001'
'0000001010011010'
'0000001010110010'
'0000001010110110'
'0000001011001100'
'0000001100000110'
'0000001100100000'
'0000001100111100'
'0000001101010100'
'0000001101110010'
'0000001110111011'
'0000001111011011'
'0000001111100000'
'0000010000000000'
'0000010000001000'
Thanks & Regards

Adam Danz on 14 Oct 2019
Edited: Adam Danz on 18 Oct 2019
The data in your question contains what appears to be a cell array of strings (or character arrays) where each string represents a binary number. If your question is how to find the position of each 1 within each string,
onePos = cellfun(@(s)strfind(s,'1'), val, 'UniformOutput', false);
This will produce a cell array of indices. onePos{n} lists the positions of '1's within the nth string of 'val'.
For example, the first row has no 1s so that cell element is empty
onePos{1}
ans =
[]
The 6th row has 1s in the 12th, 13th, and 15th character
onePos{6}
ans =
12 13 15