Concatenating multiple cells in a single matrix
显示 更早的评论
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 个评论
Jan
2021-6-9
编辑:James Tursa
2021-6-9
This is not valid Matlab code:
file = (1,((col - 1)/8) + 1) = result;
Abdallah Talafhah
2021-6-15
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!