## Conversion of multidimensional cell into string

### lavanya vs (view profile)

on 23 Apr 2019
Latest activity Edited by Stephen Cobeldick

on 23 Apr 2019

### Stephen Cobeldick (view profile)

2 [0,1,0]
73 [0,1,1,1]
97 1
108 [0,1,1,0]
109 [0,0,0,1]
110 [0,0,0,0]
118 [0,0,1,1]
121 [0,0,1,0]
This is a cell I want the array as 010
0111
1
and so on that is convert it into char for binary purpose

Guillaume

### Guillaume (view profile)

on 23 Apr 2019
Can you please use valid matlab syntax to describe your input and wanted output?
I think your input might be:
C = {2, [0,1,0];
73, [0,1,1,1];
97, 1;
108, [0,1,1,0];
109, [0,0,0,1];
110, [0,0,0,0];
118, [0,0,1,1];
121, [0,0,1,0]} %This is valid matlab syntax. We can paste this straight into matlab
I have no idea what output you want.
lavanya vs

### lavanya vs (view profile)

on 23 Apr 2019
Hello,
Thanks for replying , I want my output as
2, '010'
73 , '0111'
and so on

### Stephen Cobeldick (view profile)

on 23 Apr 2019
Edited by Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 23 Apr 2019

>> C(:,2) = cellfun(@(v)char(v+'0'),C(:,2),'uni',0)
C =
2 '010'
73 '0111'
97 '1'
108 '0110'
109 '0001'
110 '0000'
118 '0011'
121 '0010'

lavanya vs

### lavanya vs (view profile)

on 23 Apr 2019
thanks your code worked , I am new to matlab if you could help me understand the code I would learn a lot.
Thank you so much though
Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 23 Apr 2019
"...if you could help me understand the code I would learn a lot."
I used cellfun to apply a function to each vector:
C(:,2) = cellfun(@(v)char(v+'0'),C(:,2),'uni',0) % my answer, broken down:
% @(v)char(v+'0') % anonymous function [v] -> 'v'.
% C(:,2) % get second column of cell array.
% cellfun( , ,'uni',0) % iterate over each vector (cell content).
%C(:,2) = % allocate to second column of cell array.
The conversion from binary vector to character is by simply adding the character value for '0' (which is 48) onto the binary values and then converting to character. This works for any digits:
>> char([1,2,5,9]+'0')
ans = '1259'
>> char([1,2,5,9]+48) % equivalent
ans = '1259'

### Guillaume (view profile)

on 23 Apr 2019

Taking a guess here, since you're still not using matlab syntax for your example:
C = {2, [0,1,0];
73, [0,1,1,1];
97, 1;
108, [0,1,1,0];
109, [0,0,0,1];
110, [0,0,0,0];
118, [0,0,1,1];
121, [0,0,1,0]} %demo data
C(:, 2) = cellfun(@(v) char(v + '0'), C(:, 2), 'UniformOutput', false)