Basically the indexing of the R, G, B plane was missing in the if loop. Just added a few more lines and changed the type of the output variables,to verify whether the code is working.
sk=imread('skincancer1.jpg');
[m n dim]=size(sk);
hs=zeros(m,n); %initialising heaklthy skin array
nhs=zeros(m,n); %initialising non-healthy skin array
R=sk(:, :, 1);
G=sk(:, :, 2);
B=sk(:, :, 3);
for i = 1:m
for j = 1:n
if R(i,j)>150&R(i,j)>180&R(i,j)>B(i,j)&R(i,j)>G(i,j)
hs(i, j)= sk(i, j);
else
nhs(i,j)=sk(i,j);
end
end
end
imshow(uint8(nhs))
title('normal');
figure;imshow(uint8(hs))
title('cancer');


