I have the row and column indices of a rectangular region of interest in a rectangular image. How can i get the linear indices from these row and column indices?

`%this works`

a = rand(5,5); %changed.

row_indices = 1:5;col_indices = 1:5;[X,Y] = meshgrid(row_indices,col_indices);indices = sub2ind(size(a), Y, X)%i want the indices when rows and cols are not necessarily of same length.

a = rand(5,3); %changed

row_indices = 1:5;col_indices = 1:3;[X,Y] = meshgrid(row_indices,col_indices);indices = sub2ind(size(a), Y, X) %this would give out of range subscript.

## Best Answer