1
votes

I have a cell array called Event of 179X59 entries and each element is a <1X14> double

so for example Event{1,1} is a 14 bit binary number in it.. like 0 1 0 0 0 0 0 0 0 0 1 0 0 0 which is spread out through columns 1 to 14 so each columns has a bit.

Now my task is to index through each element of the cell array and get into the double and assign a particular alphabet say a for the first bit if I see 1.

So if my alphabets are A through N for a binary 1 1 1 1 1 1 1 1 1 1 1 1 1 1, need to get

A B C D E F G H I J K L M N instead of that binary number.

So for the example give in the second line 0 1 0 0 0 0 0 0 0 0 1 0 0 0 I need to get

0 B 0 0 0 0 0 0 0 0 K 0 0 0

and in the end should return B,K removing zeros.

I have tried assigning each element to a matrix and tried using strrep but its not helping me out.

3
A etc are numbers, right? - Luis Mendo

3 Answers

0
votes

Code

cellfun(@(x) cellstr(char(nonzeros(x.*[65:65+numel(x)-1])))', Event,'uni',0)

Results

For a sample Event:

Event = {
    [0 1 0 1 0 0 1] [0 1 0 1 0];
    [0 1  1 1 0] [0 0 0 1 1 1 0 0 0 0 1 1 0 1]}

Output -

>> Event{:}
ans =
     0     1     0     1     0     0     1
ans =
     0     1     1     1     0
ans =
     0     1     0     1     0
ans =
     0     0     0     1     1     1
>> out{:}
ans = 
    'B'    'D'    'G'
ans = 
    'B'    'C'    'D'
ans = 
    'B'    'D'
ans = 
    'D'    'E'    'F'

Of course, the number of columns and rows in Event at its "upper level" are maintained with out -

>> Event
Event = 
    [1x7 double]    [1x5  double]
    [1x5 double]    [1x14 double]
>> out
out = 
    {1x3 cell}    {1x2 cell}
    {1x3 cell}    {1x6 cell}
1
votes

Without removing zeros:

alphabet = [11:24]; %// numbers. Replace values as needed
resultzeros = bsxfun(@times, alphabet, vertcat(Event{:}));
resultzeros = reshape(mat2cell(resultzeros, ones(1, size(resultzeros,1))), size(Event));

If you then need to remove zeros:

result = cellfun(@(x) nonzeros(x).', resultzeros, 'uni', 0);

Or directly:

result = cellfun(@(x) alphabet(x~=0), Event, 'uni', 0);

Example:

>> Event = {[0 0 1 0], [1 1 1 1]; [1 1 0 0], [0 0 1 1]};
>> alphabet = [4 5 6 7];

gives

result{1,1} =

     6

result{2,1} =

     4     5

result{1,2} =

     4     5     6     7

result{2,2} =

     6     7
0
votes

I suppose that time is not critical, so you can at least loop. Rough sketch:

alphabet = {A, B, C, D, E...}

j= 0;
for i=1:nBit
  if( Event{1,1}(i) == 1)
    EventAlphabet{1,1}{j} = alpabet{i};
    j = j + 1;
  end
end

Your question is a little bit unclear, so my answer is a rough sketch that may help you nontheless.