Concatenating multiple cells in a single matrix
Afficher commentaires plus anciens
I'm trying to hide files in a float64 DCT2 array; I have the stream of bits in a single 1*x array where each cell includes a single bit. I'm already able to concatenate bits into bytes successfully by using a for loop, 8 placeholder variables, and strcat.
for col = 1 : 8 : bitStreamSize(2) - 7
bit0 = bitStream(1,col);
bit1 = bitStream(1,col + 1);
bit2 = bitStream(1,col + 2);
bit3 = bitStream(1,col + 3);
bit4 = bitStream(1,col + 4);
bit5 = bitStream(1,col + 5);
bit6 = bitStream(1,col + 6);
bit7 = bitStream(1,col + 7);
result = strcat(num2str(bit0),num2str(bit2),num2str(bit2),num2str(bit3),num2str(bit4),num2str(bit5),num2str(bit6),num2str(bit7));
result = bin2dec(result);
file(1,((col - 1)/8) + 1) = result;
end
This works fine for when you know how many bits you're dealing with, but now I want to do the same thing somewhere else in my project where the user inputs a number from 1 to 63 and then that number of bits will be concatenated into a single cell. I thought of using a switch statement but MATLAB does not use break; like C++ so I'd have to repeat the code 63 times; this would be a very clunky implementation and it'd be very hard to modify.
Is there a more effecient/modular way of concatenating a given number of bits without having to redo everything for every single possible number?
2 commentaires
Jan
le 9 Juin 2021
Modifié(e) : James Tursa
le 9 Juin 2021
This is not valid Matlab code:
file = (1,((col - 1)/8) + 1) = result;
Abdallah Talafhah
le 15 Juin 2021
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!