lundi 27 avril 2015

How to specify a range and perform a function accordingly in matlab?

I need to perform the following function in matlab.

enter image description here

I had tried the following code but somehow my if statement is wrong. I'd like to know how to use the if statement efficiently here. If there is any other method in which i could perform the function please do help. My code is as follows

if (y(i,j) < -0.5, y(i,j) >= -1)
    f(i,j) = 0
elseif (y(i,j) < 0, y(i,j) >= -0.5)
    f(i,j) = 1
elseif (y(i,j) < 0.75, y(i,j) >= 0)
    f(i,j) = 2
elseif (y(i,j) < 1, y(i,j) >= 0.75)
    f(i,j) = 3
end

Here y(i,j) is a 1 x 256 matrix. Thanks

Aucun commentaire:

Enregistrer un commentaire