MATLAB: Converint between Cell arrays and Numbers and Strings

cell arraycellschardoubleuint8

Hello,
I am trying to convert a double cell array as shown to individual 8 bit cells. (I hope I have been able to frame the question correctly, if not please take a look at my screenshot)
I want to convert each contents to individual bits, like for e.g [10000111] to individual 1 0 0 0 0 1 1 1
I have tried everything from cell2num, mat2cell, cell arrays and all but keep getting errors.
Please help me in solving this; also a little background theory on what these types of cells and 'cellarrays' mean would be a great help for next time!
Thanks,
Cheers,
kash022

Best Answer

This obtains the digits of a decimal number:
x = 10000111;
n = floor(log10(x));
out = rem(floor(x(:) ./ power(10, n:-1:0)), 10)
>> [1 0 0 0 0 1 1 1]
I prefer this instead of the indirection of letting sprintf convert the number to a char vector and converting it back to a number.
"Cell arrays" are arrays of the class cell. These are array, which can contain elements of different sizes and classes. See:
doc cell
Example:
C = {[], 1, 1:2, 1:3, 'And a char vector also'}
If you want to store the output in one array and do not want leading zeros, you need a cell array, because the vectors have dirrent length.
x = [1, 101, 10000111];
C = cell(size(x));
nMax = floor(log10(max(x)));
P = power(10, nMax:-1:0); % Expensive power operation once only
for k = 1:numel(x)
n = floor(log10(x(k)));
C{k} = rem(floor(x(k) ./ P(nMax-n+1:end)), 10);
end
Note: You are working with Matlab since at least March 2016. You are expected to be able to read the documentation of the cell command.