Index in position 3 exceeds array bounds (must not exceed 3) in horizontal (i,ma,j)=consistency(i+1,ma,j)*consistency(i,ma,j); what is mean this error ?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
local=rangefilt(cb_component,true(3));%local range of pixel intensity
reshape(local,[512,3]);
mean=mean2(double(local));%mean
sdImage = stdfilt(local, true(3));%standard devieation
Variance_final = mean2(var(double(local)));%varience
%sdImage = stdfilt(cb_component, true(3));% Now sdImage is the std dev within a 3-by-3 window around each pixel.
variace=var(double(local)) ;
[mr,ma,mc]= size(local);
consistency=zeros(mr,ma,mc);
for i=1:1:mr
for j=1:1:mc
consistency(i,ma,j)= (local(i,ma,j)-mean )/(Variance_final+1);
end
end
%horizontial direction feature
horiz=zeros(mr,ma,mc);
for i=1:1:mc
for j=1:1:mr
horiz(i,ma,j)=consistency(i+1,ma,j)*consistency(i,ma,j);
end
end
0 comentarios
Respuestas (1)
sanidhyak
el 20 de Feb. de 2025
I understand that you are encountering the error "Index in position 3 exceeds array bounds (must not exceed 3)" while running your MATLAB code to compute the horizontal direction feature.
When running the code provided by you, I too faced a similar issue. This error occurs because the code tries to access an index that exceeds the array dimensions. In this case, the issue arises from the line:
horiz(i, ma, j) = consistency(i + 1, ma, j) * consistency(i, ma, j);
Here, the index “i + 1” can exceed the bounds of the consistency array, especially when “I” reaches its maximum value (“mr”), leading to an “out-of-bounds” error.
Kindly refer to the following corrected part of the code:
% Horizontal direction feature
horiz = zeros(mr, ma, mc);
for i = 1:mr - 1 % Loop till mr - 1 to avoid i+1 out of bounds
for j = 1:mc
horiz(i, ma, j) = consistency(i + 1, ma, j) * consistency(i, ma, j);
end
end
Now, loop would run from ‘1” to “mr – 1”, making sure that “i + 1” never exceeds the array bounds.
Kindly refer to the official documentation on array indexing in MATLAB for further details:
I hope this helps!
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!