NOTE: this is an answer to the original question; the second edit changed the question completely, so the answer below no longer applies. The edit greatly simplifies the problem, so this answer is still a good place to start.
Basically, all unique values of a will be replaced by corresponding values in b. That implies the matrix to analyze is b, and the only difficulty lies in the fact that the condition b < d must hold for corresponding indices in b.
To do this, you can simply bin all elements of a in groups defined by c and determine what group each element in b belongs to. That information can be used to find the proper indices in d.
In other words:
NewMat = b;
[~, inds] = histc(a(:), c);
NewMat(NewMat(:) > d(inds)) = 0;
A small test to compare the performance and validate the equality of the two methods:
a = randi(1000, 74,100);
b = randi(1000, 74,100);
c = unique(a);
d = randi(1000, size(c)); % some comparison Values
%// Your method
tic
NewMat = zeros(size(a));
for i = 1:length(c)
Mat = zeros(size(a));
Mat(a==c(i)) = b(a==c(i));
Mat(Mat > d(i)) =0;
NewMat = NewMat + Mat;
end
NewMat1 = NewMat;
toc
%// My method
tic
[~,inds] = histc(a(:), c);
b(b(:) > d(inds)) = 0;
NewMat2 = b;
toc
%// validate solution
isequal(NewMat1, NewMat2)
Results:
%// 74 × 100
Elapsed time is 0.151808 seconds. %// your method
Elapsed time is 0.001007 seconds. %// my method
ans = %// yes, they're equal
1
So a factor of ~150 performance increase. Using not 74×100 but 740×1000 gives
%// 740 × 1000
Elapsed time is 27.587543 seconds. %// your method
Elapsed time is 0.111467 seconds. %// my method
ans = %// yes, they're equal
1
or a factor of ~250 difference. So apparently, your method also scaled worse than the histc approach.