필터 지우기
필터 지우기

why is an error in this matrix??

조회 수: 2 (최근 30일)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 4월 5일
편집: MHN 2016년 4월 5일
if i have this matrix
M =[ 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1
1 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1
1 1 0 1 0 0 0 0 0 0 0 1 1 1 1 1
0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 1
0 1 1 1 1 0 1 0 0 1 1 1 1 1 0 1
0 0 1 1 0 1 1 0 1 1 1 0 1 0 0 1
0 1 0 0 1 0 1 1 1 1 0 1 1 1 0 1
0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 ]
with this code
[n,m]=size(M);
c1=cell(n,m);
maxc=1;
for k=1:m
a=[0 M(:,k)' 0];
ii1=strfind(a,[0 1]);
ii2=strfind(a,[1 0]);
maxc=max(maxc,numel(ii1));
c1{k}=(ii2-ii1)';
end
M_column=cell2mat(cellfun(@(x)[zeros(1,maxc-numel(x));x],c1,'un',0));
  • when i run this code ,, the error occurs in M_column
how i can solve it????

채택된 답변

MHN
MHN 2016년 4월 5일
편집: MHN 2016년 4월 5일
Your vectors in c1 are m*1 matrices, so you should make n*1 zeros matrices instead of 1*n.
M_column=cell2mat(cellfun(@(x)[zeros(maxc-numel(x),1);x],c1,'un',0));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by