早教吧 育儿知识 作业答案 考试题库 百科 知识分享

MATLAB中的错误???Subscriptindicesmusteitherberealpositiveintegersorlogicals.data;bound=zeros(length(dat(:,1)),length(dat(1,:)));fori=1:length(dat(:,1))forj=1:length(dat(1,:))ifdat(i,j)==1ifdat(i-1,j)==1&dat(i+1,j)==1&amp

题目详情
MATLAB中的错误??? Subscript indices must either be real positive integers or logicals.data; bound=zeros(length(dat(:,1)),length(dat(1,:))); for i=1:length(dat(:,1)) for j=1:length(dat(1,:)) if dat(i,j)==1 if dat(i-1,j)==1 & dat(i+1,j)==1 & dat(i,j-1)==1 & dat(i,j+1)==1 bound(i,j)=0; else bound(i,j)=1; end else bound(i,j)=0; end end end %检测孤立点 for i=1:length(dat(:,1)) for j=1:length(dat(1,:)) if dat(i,j)==1 if dat(i-1,j)==0 & dat(i+1,j)==0 & dat(i,j-1)==0 & dat(i,j+1)==0 & dat(i- 1,j+1)==0 & dat(i-1,j-1)==0 & dat(i+1,j+1)==0 &dat(i+1,j-1)==0 bound(i,j)=0; end end end end clear i;clear j;
▼优质解答
答案和解析
由于你的i和j是从1开始的,而是用中用到了i-1和j-1此时为0,但matlab得下标只能是正整数,所以报错