MATLAB: Convert binary column vector to decimal

bin2decsort

I'm trying to convert each column of a matrix A of ones and zeros to their corresponding decimal value and sort the decimal values in a new (1xn) matrix B. For eg. A=[100;011,101] B=[5 2 3] This is for a matrix A of size 52×15 and matrix B of size 1×15.

Best Answer

A simple way can be:
close all; clear all; clc
% Created matrix with 0 and 1
matrix = rand(52,15) ;
matrix(matrix<=0.5) = 0;
matrix(matrix>=0.5) = 1;
% Save memory
decim = zeros(1,size(matrix,2));
% Begin string empty
S=[];
% For each column
for j = 1:size(matrix,2)
% Get the column
column = matrix(:,j)';
% Concatenate the numbers
for i = 1:size(matrix,1)
S = [S num2str(column(i))];
end
% Save the value dec
decim(1,j) = bin2dec(S);
% Empty String
S=[];
end
% Sorted tge results
sorted = sort(decim);
I hope to help.