Reputation: 726
I'm trying to add two matrices together. They are both 400x400. Here's the bit of code that's giving me trouble:
greys = (r+g+b)./3;
fc = cat(3, r, g, b);
combined = (greys+fc)./2; <---error occurs here
But when my code gets to the greys+fc part, it throws an error. This error:
Error using +
Matrix dimensions must agree.
Error in imgSimpleFilter (line 36)
combined = (greys+fc)./2;
when I print the number of rows and columns in both the grey and fc matricies, I get 400 for all of the values (which is exactly as I expected, as I am working with a 400x400 image).
Why isn't it letting me add these together?
I have no problems with the line
greys = (r+g+b)./3;
and that's adding three 400x400 matrices together. Any ideas?
Upvotes: 0
Views: 75
Reputation: 4549
You can't add them because greys
is 400x400, while fc
is 400x400x3.
Try typing size(greys)
and size(fc)
on the command line, or whos greys fc
to see it.
If you want to "combine" them by averaging them, you could use bsxfun:
combined = bsxfun(@plus, greys, fc) ./ 2;
Upvotes: 3