how to correct this error?

for x=1:rows
for y=1:cols
wt(x,y)=t1(x,y)/max(t1(x,y));
end
end
c=norm(double(wt.*(eimg1(x,y)-eimg(x,y))))/norm(double(wt.*eimg(x,y)));
For the last line,
Error using .*
Integers can only be combined with integers of the same class, or scalar doubles.
I want this norm value to use as a condition in a loop eimg eimg1 are matrices of an image. wt is the weight function. t1 is the suppression term at the first iteration.

Answers (1)

You have
wt(x,y)=t1(x,y)/max(t1(x,y));
Your x and y are scalars, so your t1(x,y) is going to be a scalar, and max() of a scalar is the scalar itself. Your wt() calculation is always going to result in 1 for every location. If t1 is floating point then your wt is going to be floating point; if your t1 is integer, your wt would be integer of the same class.
My guess is that you should replace your double loop with the single line
wt = double(t1) ./ double( max(t1) );
This would give you an array of floating point.
If your eimg1 and eimg are your images, they are probably integer class. In that case you would need to replace
c=norm(double(wt.*(eimg1(x,y)-eimg(x,y))))/norm(double(wt.*eimg(x,y)));
with
c = norm(wt .* (double(eimg1) - double(eimg))) / norm(wt .* double(eimg));
Notice here that I did not subscript with x and y: you are outside the loops at this point so x and y are nearly meaningless. Notice also that I used double() before subtracting: when you subtract two items of integer class, the result might not be what you expect.

7 Comments

Error using .* Matrix dimensions must agree.
Error in mainw>pushbutton3_Callback (line 196)
c = norm(wt .* (double(eimg1) - double(eimg))) / norm(wt .* double(eimg));
You need ./ not just /
c = norm(wt .* (double(eimg1) - double(eimg))) ./ norm(wt .* double(eimg));
What is size(eimg) and size(wt) ? What size of output are you expecting for c ?
eimg and wt are the size the image loaded
The norm() calls will return scalars so ./ should not be needed. And the error message was about .* not about /
Please show the exact values of
rows
cols
size(t1)
size(wt)
size(eimg1)
size(eimg)
And also please say what size you are expecting "c" to be when it is calculated.
the sizes vary with the size of any image inputted the condition for the loop is c > 7 * 10 ^ -6
You posted above that you received an error with .* in executing my code. For that particular combination of inputs, I need you to show the values I requested above. If you do not show the exact values associated with an occurrence of the error message, I will not be able to assist you further.

Sign in to comment.

Asked:

on 10 Jan 2017

Commented:

on 10 Jan 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!