Reading data in cell arrays help

1 view (last 30 days)
Hi There was this line in a program code.
for k = 1:9
[i,j] = ind2sub([3,3],k);
Output(:,:,indx+k) = AccessImageDiff{row,col}(i:end-3+i,j:end-3+j);
Now my problem is how do i read this line? Can somebody teach me on how to read this specific line
  • Output(:,:,indx+k) = AccessImageDiff{row,col}(i:end-3+i,j:end-3+j);*
i know that it is accessing a cell array and manipulating its data but what i am confused about is the (i:end-3+i,j:end-3+j) part.
1.what does ":" mean?
2.what does "end" mean? It didn't use end as a variable.
Thanks in advance
There's this tutorial about accessing data in cell arrays but it doesn't really answer my question

Accepted Answer

Star Strider
Star Strider on 30 Jul 2017
‘... what i am confused about is the (i:end-3+i,j:end-3+j) part.’
Here, end is the size of the array in that dimension. See the documentation on end (link) for a full description, specifically:
  • The end function also serves as the last index in an indexing expression. In that context, end is the same as size(X,k) when used as part of the kth index into array X. Examples of this use are X(3:end) to select the third through final elements of the array, and X(1,1:2:end-1) to select all even elements of the first row, excluding the last element. When using end to grow an array, as in X(end+1)=5, make sure X exists first.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by