MATLAB: How to use the row&column indices returned by find to control array element in matrix way

MATLABmatrix manipulation

I have a logical matrix (X) that are generated when the element meets certain conditions in the original raw matrix (data) and use "find" function to find the row and column indices for those elements. After that, I would like to achieve some operations on the neighbour elements of the original matrix. But I can't achieve it in the matrix method. Could anyone please give me some suggestions? The issue is illustrated as below:
For example:
[Y,X]=meshgrid(y_1grid,x_1grid);
% X size is (ie,je)
X= (X.^2 + Y.^2) <= (diam/2.0)^2 ;
% for instance, ie=7, je=7
X=[ 0 0 0 0 0 0 0;
0 0 0 1 0 0 0;
0 0 1 1 1 0 0;
0 1 1 1 1 1 0;
0 0 1 1 1 0 0;
0 0 0 1 0 0 0;
0 0 0 0 0 0 0];
[row, col]=find(X==1);
% ex and data are same size as X
ex(row,col)=ex(row,col)+0.5*(data(row,col)-data(row,col-1)); % this is wrong
% correct way, but the efficiency is too slow
for ii=1: ie
for jj=2:je
if ismeber (ii,row) && ismember (jj,col)
ex(ii,jj)=ex(ii,jj)+0.5*(data(ii,jj)-data(ii,jj-1);
else
ex(ii,jj)=ex(ii,jj)+0.1*(data(ii,jj+1)-data(ii,jj);
end

Best Answer

One of the way could be to use absolute indexing of X matrix :
ind = find(X==1);
ex(ind)=ex(ind)+0.5*(data(ind)-data(ind-je)); % je = size(X,1);
I hope it helps !