mardi 7 juillet 2015

Matlab simple matrix manip

I'm new to Matlab and I want to achieve a very simple operation : I have a 792 x 1046 uint8 matrix called mg and want to convert its cells values (from 0 to 255) to values between 1 and 4 (1,2,3,4) in a new matrix called mgc accordingly to simple conditions.

Strangely, the new matrix is filled with only 1s and 2s but not any 3s or 4s...

Here is my code :

[x,y]=size(mg);
mgc = zeros(x,y);

for i=1:x
    for j=1:y
        if (mg(i,j)<=100) 
            mgc(i,j)=1;
        elseif (100<mg(i,j)<=110) 
            mgc(i,j)=2;
        elseif (110<mg(i,j)<=120) 
            mgc(i,j)=3;
        else
            mgc(i,j)=4;
        end
    end
end

If anyone could help me solve this stupid issue, it would be great ! THX

Aucun commentaire:

Enregistrer un commentaire