What I have
I've a char array, defined by doing an strcat between two char arrays like this:
coeficientes = strcat(coef_bin, coef_bin_comp)
Then, I want to read each row and convert them to hex. I'm doing it like:
for k=1:11
coef_binario = coeficientes(1+(k-1)*8:k*8);
coef_hexadecimal = binaryVectorToHex( coef_binario - '0' );
fprintf('%s\t%s\n', coef_binario, coef_hexadecimal);
end
What's the result
If I print both coeficientes variable and each coef_binario I take to convert, results are the following:
Note: coeficientes is printed by just removing semicolon after strcat line, but coef_binario is printed by using fprintf as is written above.
coeficientes =
00011111 00111101 01001100 01011011 01111001 10001000 10010111
10110101 11000100 11010011 11110001
00000111 07 11100111 E7 00011101 1D
00100100 24 11101101 ED 10111111 BF
11000001 C1 11000111 C7 00100100 24
10010110 96 11011011 DB
The Problem
As you can see, I've tried to read the coeficientes var row by row using:
coef_binario = coeficientes(1+(k-1)*8:k*8);
But when it's printed, binary code doesn't match with the original one. Any idea about why or how can I do it in order to have it correctly?
Update 1
If I try to split it before doing it, in order to use strsplit before I need to get the string. I've tried:
strs = strsplit(sprintf('%s', coeficientes), ' ')
From this, I obtain again the wrong chain. In fact, after using just sprintf (and not strsplit), what I get is:
0000011111100111000111010010010011101101101111111100000111000111001001001001011011011011
Update 2
How coeficientes is generated:
% coef_k is a vector of decimal numbers, i.e.: [1 3 5 8 11 14]
coef_bin = dec2bin(coef_k);
coef_complementario = 16 - coef_k;
coef_bin_comp = dec2bin(coef_complementario);
coeficientes = strcat(coef_bin, coef_bin_comp)
coeficientesis. Is it a string? A cell array of strings? Can you add an actual Matlab statement that would producecoeficientesthat we can use.