title: Alternative to `ismember` and `intersect` in Matlab to perform the task of comparison?
body: <p>I have 100 models (matrices), where each matrix's size is 4X3. Each of the four variables <code>R_L</code>, <code>N_g</code>, <code>N_Pc</code>, and <code>uT</code> are of size 4x3x100, where 4X3 is size of each matrix and there are 100 of such matrix. I have attached a snapshot of two variables to give an idea of what I mean:</p>
  
  <p><img src="https://i.stack.imgur.com/lkjfm.jpg" alt="enter image description here"></p>
  
  <p>I am looping through matrix 1 of first three variables (i.e. <code>R_L</code>, <code>N_g</code>, <code>N_Pc</code>) and comparing each element in matrix 1 of these variables with elements in other 99 matrices. I want to find those elements where all three variables in those 99 matrices are equal to corresponding three variables in any element of matrix 1. </p>
  
  <p>For example, if all three variables in element (1,1) of matrix 1 have correspondingly similar values in element (2,2) of matrix 2, (2,1) of matrix 3, (2,4) of matrix 3 etc. then I will pick the results from variable 4 (i.e. <code>uT</code>) at all those above element positions i.e. (1,1) of matrix 1, (2,2) of matrix 2, (2,1) of matrix 3, (2,4) of matrix 3  etc from <code>uT</code> and store those results in a new variable called <code>store_result</code> to plot its histogram. It is shown in code below.</p>
  
  <pre><code>nModel=100;
  ixk=1;
  % looping inside model # 1
  for k_model1=size(R_L,1):-1:1
      for i_model1=1:size(R_L,2)
  
          % comparing values in model 1 to values in model 2 to nModel
          for model_no=2:nModel
              % looping inside each model from model # 2 to nModel
              for k=size(R_L,1):-1:1
                  for i=1:size(R_L,2)
                      if ismember(R_L(k_model1,i_model1,1), R_L(k,i,model_no)) &amp;&amp;...
                              ismember(N_g(k_model1,i_model1,1), N_g(k,i,model_no)) &amp;&amp;...
                              ismember(N_Pc(k_model1,i_model1,1), N_Pc(k,i,model_no))
                          index_for_identical_results(:,:,model_no)=intersect(ismember(R_L(k_model1,i_model1,1), R_L(k,i,model_no)),...
                              ismember(N_g(k_model1,i_model1,1), N_g(k,i,model_no)),...
                              ismember(N_Pc(k_model1,i_model1,1), N_Pc(k,i,model_no)));
  
                      end
                  end
              end
          end
          store_result(:,ixk)=uT(index_for_identical_results(:,:,model_no));
          ixk=ixk+1;
      end
  end
  </code></pre>
  
  <p>I have following concerns that I would like to be addressed:</p>
  
  <ol>
  <li><p><code>ismember</code> would be useful only when the values match exactly. In case there are no exact similar values, what would you suggest if I would like to give certain interval within which the values fall then it should be considered equal.</p></li>
  <li><p>Since I want to find a grid (element) where all three variables are equal, therefore the function <code>intersect</code> would not work here (even though I have used in the code above). What would you suggest to use instead of <code>intersect</code> which can perform the similar function with multiple variables.</p></li>
  </ol>
  
  <p>Thanks.</p>