Indexing cannot yield multiple results.

Hello, so I have this code, for a 3x3 rgb image:
[nRows, nCols, nCh] = size(image);
%I have 100 3x3 squares of the image:
p = zeros(3,3,3)
P = cell(100,1);
k = 0;
for i=1:3:nRows
for j=1:3:nCols
k = k+1;
p = image(i:i+2, j:j+2, :);
P{k} = p;
if k>=100
break;
end
end
end
%average for the 67th square:
p = P{67};
m(67) = [sum(sum(p(:,:,1))/9), sum(sum(p(:,:,2))/9), sum(sum(p(:,:,3))/9)];
And at the first row [nRows, nCols, nCh] = size(image) I get the Indexing error. Any ideas? Thank you

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 17일
편집: Azzi Abdelmalek 2016년 4월 17일

0 개 추천

Check if size was not used as a variable. For example
size=2
[n,m]=size(rand(4))
To resolve the problem type
clear size
[n,m]=size(rand(4))

댓글 수: 2

Cezarina Croitoru
Cezarina Croitoru 2016년 4월 17일
it's not used at all, only in that line
In Matlab Windows Command, type
which size

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2016년 4월 17일

댓글:

2016년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by