Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Finding bit's postions in cell

1 visualizzazione (ultimi 30 giorni)
Ranjit Kumar Chennamchetty
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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

Risposte (1)

Adam Danz
Adam Danz il 14 Ott 2019
Modificato: Adam Danz il 18 Ott 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

Community Treasure Hunt

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

Start Hunting!

Translated by