Simple solution - you can change your loop directly to one arrayfun call. arrayfun is a fancy way of writing a loop - it calls user-defined function for all supplied parameters. The caveat is that anonymous functions that one usually uses with arrayfun can not assign variables. But, you can write a normal function that assigns color to img and pass it to arrayfun as parameter:
function doAllWork(img, rightIdx, leftIdx)
arrayfun(@fill, 1:size(img, 1));
function fill(i)
img(leftIdx(i):rightIdx(i), i) = color;
end
end
I have defined the fill function as a local function in doAllWork so that it has access to img, leftIdx, rightIdx.
Complicated solution Usually in such cases, to do an assignment in one go you want to use sub2ind to get a linear index into the matrix (in short, in C you would write sth. like j*nx+i). You then write img(ind) instead of img(indrow, indcol). The problem is that every row has a different number of non-zeros in different places.
The (complicated) idea is to create an explicit column index array Ii{row} = [leftIdx(row):rightIdx(row)] and corresponding row index array Ij{row} = [row*ones(1, lenght(Ii{row}))] for all rows. Without a loop that can be done using arrayfun. Once you have this, you can construct a linear index into your img using sub2ind on coresponding Ii/Ij entries, also called using arrayfun. The code looks like this
nrows=1:size(img, 1);
Ii=arrayfun(@(i)(leftIdx(i):rightIdx(i)), nrows, 'UniformOutput', false);
Ij=arrayfun(@(i)(i*ones(1,length(Ii{i}))), nrows, 'UniformOutput', false);
lin=arrayfun(@(i)(sub2ind(size(A), Ij{i}, Ii{i})), nrows, 'UniformOutput', false);
img([lin{:}])=color;
This approach is not of much use in your case - it is way too complicated. But it is instructive in what arrayfun can do, and the trick with sub2ind is generally very useful.