Binary three-dimensional fuzzy matrix in matlab

I have a fuzzy matrix M whose size is 3x3x3such that

M(:,:,1)+M(:,:,2)+M(:,:,3)=matrix one %all elements is one
0<=M(:,:,i)<=1; i=1..3

I want to hide the matrix M to a binary matrix such that

if (M(p,q,i)>=M(p,q,j)) then M(p,q,i)=1, M(p,q,j)=0

where p, q is the position of the element. i, j = 1..3

Please note that if we have already installed M(p,q,i)=1, then there M(p,q,j)should be 0(j = 1..3, j! = I), because I want to sum the binary matrix M, which is still 1 (sum (M, 3) = those ( 3, 3))

Could you help me fulfill this idea in Matlab? Thank you very much.

For instance:

M=zeros([3 3 3]);
M(:,:,1) =  [0.2000    0.3000    0.4000;
             0.5000    0.6000    0.7000;
             0.3000    0.2000    0.1000];


M(:,:,2) =  [0.4000    0.1000    0.6000;
             0.1000    0.3000    0.1000;
             0.1000    0.2000    0.1000];


M(:,:,3) =  [0.4000    0.6000         0;
             0.4000    0.1000    0.2000;
             0.6000    0.6000    0.8000];

My expected result

M_out(:,:,1)=[0        0         0;
              1        1         1
              0        0         0];

M_out(:,:,2)=[1        0         1;
              0        0         0
              0        0         0];

M_out(:,:,3)=[0        1         0;
              0        0         0
              1        1         1];
+4
source share
3 answers

Let bsxfunand the permuteduo decide to solve it generic, and vectorized-

%// Get max indices along dim-3
[~,idx] = max(M,[],3);

%// Setup o/p logical array with same size as M and 1s at starting max indices
M_out = bsxfun(@eq,idx,permute(1:size(M,3),[1 3 2]))

Run Example -

>> M
M(:,:,1) =
          0.2          0.3          0.4
          0.5          0.6          0.7
          0.3          0.2          0.1
M(:,:,2) =
          0.4          0.1          0.6
          0.1          0.3          0.1
          0.1          0.2          0.1
M(:,:,3) =
          0.4          0.6            0
          0.4          0.1          0.2
          0.6          0.6          0.8
>> [~,idx] = max(M,[],3);
M_out = bsxfun(@eq,idx,permute(1:size(M,3),[1 3 2]))
M_out(:,:,1) =
     0     0     0
     1     1     1
     0     0     0
M_out(:,:,2) =
     1     0     1
     0     0     0
     0     0     0
M_out(:,:,3) =
     0     1     0
     0     0     0
     1     1     1
+5
source

. , , N

M12=M(:,:,1)>=M(:,:,2);
M13=M(:,:,1)>=M(:,:,3);
M_out(:,:,1)=M12.*M13

M21=M(:,:,2)>M(:,:,1); %"we already set M(p,q,i)=1 then M(p,q,j) must be 0 (j=1..3, j!=i)"
M23=M(:,:,2)>=M(:,:,3);
M_out(:,:,2)=M21.*M23

M31=M(:,:,3)>M(:,:,1);% "we already set M(p,q,i)=1 then M(p,q,j) must be 0 (j=1..3, j!=i)" 
M32=M(:,:,3)>M(:,:,2);% "we already set M(p,q,i)=1 then M(p,q,j) must be 0 (j=1..3, j!=i)"
M_out(:,:,3)=M31.*M32

%%Checking
sum(M_out,3)
0

this code does almost the same thing you asked for, the only difference is that when max is the same (i.e.M (p, q, i) == M (p, q, j)), it records from 1 to both locations (i and j).
Here is the code:

M=zeros([3 3 3]);
M(:,:,1) =  [0.2000    0.3000    0.4000;
             0.5000    0.6000    0.7000;
             0.3000    0.2000    0.1000];


M(:,:,2) =  [0.4000    0.1000    0.6000;
             0.1000    0.3000    0.1000;
             0.1000    0.2000    0.1000];


M(:,:,3) =  [0.4000    0.6000         0;
             0.4000    0.1000    0.2000;
             0.6000    0.6000    0.8000];

output = zeros(size(M));
for i = 1:size(M,1)
    for j = 1:size(M,2)
        for k = 1:size(M,3)
            if M(i,j,k) == max(M(i,j,:))
                output(i,j,k) = 1;
            else
                output(i,j,k) = 0;
            end
        end
    end
end

Please tell me if this works for you or if you post 1 in both places, this is a problem for you.

0
source

Source: https://habr.com/ru/post/1598340/


All Articles