MATLAB: Error message:in an assignment A(i) =b the number of elements in b and i must be same

colorgroup(p)=group

clc;
im=lmread('peppers.tif');
[row col byt]=size(im);
a=im(:,:,1);
b=im(:,:,2);
c=im(:,:,3);
a=double(a);
b=double(b);
c=double(c);
for x=1:1:row
for y=1:1:col
new=(a(x,y)+b(x,y)+c(x,y))/3;
new1=0.3*a(x,y)+0.59*b(x,y)+0.11*c(x,y);
end
end
figure (1)
imshow(uint8(im))
figure (2)
imshow(uint8(new))
figure (3)
imshow(uint8(new1))

Best Answer

clc; clear all ;
im=imread('peppers.tif');
[row, col, byt]=size(im);
a=im(:,:,1);
b=im(:,:,2);
c=im(:,:,3);
a=double(a);
b=double(b);
c=double(c);
new = zeros(row,col) ;
new1 = zeros(row,col) ;
for x=1:1:row
for y=1:1:col
new(x,y)=(a(x,y)+b(x,y)+c(x,y))/3;
new1(x,y)=0.3*a(x,y)+0.59*b(x,y)+0.11*c(x,y);
end
end
figure (1)
imshow(uint8(im))
figure (2)
imshow(uint8(new))
figure (3)
imshow(uint8(new1))
I don't think the above shows any error. If you face error still, attach your image peppers.tif .And also you have not mentioned line number where you faced error.