% M_row to return the number of ones in each row
% M_column to return the number of ones in each column
M =[ 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 1 1 1 1 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 1 0 0 1 1 1 1 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 1 1 0 1 1 0 1 0 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 0 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 ];[n_M,m_M]=size(M);b_M=cell(n_M,1);c_M=cell(1,m_M);maxb=1;maxc=1;for k=1:n_M a=[0 M(k,:) 0]; ii1=strfind(a,[0 1]); ii2=strfind(a,[1 0]); maxb=max(maxb,numel(ii1)); b{k}=ii2-ii1;endfor k=1:m_M a=[0 M(:,k)' 0]; ii1=strfind(a,[0 1]); ii2=strfind(a,[1 0]); maxc=max(maxc,numel(ii1)); c_M{k}=(ii2-ii1)';endM_row=cell2mat(cellfun(@(x) [x zeros(1,maxb-numel(x))],b_M,'un',0));M_column=cell2mat(cellfun(@(x)[zeros(maxc-numel(x),1);x],c,'un',0));%%find the sum numbers in each column and count them
% x to return the sum of the number
% w to return number of element in each column
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Col=(n_M+repmat(1:n_M,m_M,1)-A'.*cumsum(A',2)).*A';for k=1:m_M a=Col(k,Col(k,:)~=0); [~,~,kk]=unique(a); col1{k,1}=accumarray(kk,1);endcelldisp(col1)
MATLAB: How to correct this error
duplicate post requiring mergingmatrix
Related Question
- Counting consecutive repeat values for each row in matrix
- If i have two binary matrix how can calculate the similarities between them
- Summing specific pixel values
- This error happened when i run genetic algorithm
- How can i sort columns of a matrix in ascending order using loops without using the functions max,min,sort
- Select random data from a matrix and replace it
Best Answer