Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Finding bit's postions in cell
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Adam Danz
2019년 10월 14일
편집: Adam Danz
2019년 10월 18일
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
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!