Command to pad zeros to specific locations in binary numbers?

后端 未结 5 1507
孤独总比滥情好
孤独总比滥情好 2021-01-07 02:48

I need to pad zeros to specific locations in binary numbers. Looping the array form of a binary number such as dec2bin(43) and adding the zeros and adjusting th

5条回答
  •  猫巷女王i
    2021-01-07 03:40

    If you are looking for efficiency it can never hurt to try various options. Here is another way to do it:

    M = magic(5)>3; % Example matrix
    positions = [2 3 6]; % Desired padding columns in resulting matrix
    
    n = size(M,2)+numel(positions);
    R = false(size(M,1),n);
    
    R(:,setxor(positions,1:n))=M
    

提交回复
热议问题