daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [m,n]=size(D);
  2.     for i=1:m-1
  3.     if D(i,1)==D(i+1,1)
  4.     D=reshape(D, 2, m/2*n);
  5.     D=(D(i,:)+D(i+1,:))/2;
  6.     D=reshape(D, m/2, n);
  7.      else
  8.       end
  9.     end
  10.    
  11. for row=0,row++
  12.  
  13.     if ( m[row,1]  == m[row+1,1])
  14.     {
  15.         mean1 = mean(m[row]);
  16.         mean2 = mean(m[row+1]);
  17.         mean = mean(mean1,mean2);
  18.     }
  19.  
  20. end for
  21.    
  22. index_row = 1:1:size(D, 1); % linear row index
  23. index_valid = all(~diff(D(:,1:2)), 2); % valid rows (logical)
  24.  
  25. mean_matrix = (D(1:end-1,:) + D(2:end,:))/2; % matrix of all means
  26.  
  27. % matrix of valid mean rows only
  28. mean_matrix_valid = mean_matrix(index_valid,:); % logical index
  29. % linear index of valid rows, i.e. the pairs indexed (i, i+1)
  30. index_row_valid = index_row(index_valid); % valid rows (int)
  31.    
  32. D = [1 2 3 4 5; 1 1 1 1 1; 1 2 4 4 4; 1 2 3 3 3; 2 2 2 2 2; 2 2 3 3 3];
  33.  
  34. >> D =
  35.      1     2     3     4     5
  36.      1     1     1     1     1
  37.      1     2     4     4     4
  38.      1     2     3     3     3
  39.      2     2     2     2     2
  40.      2     2     3     3     3
  41.    
  42. >> index_valid =
  43.  
  44.      0
  45.      0
  46.      1
  47.      0
  48.      1
  49.  
  50. >> index_row_valid =
  51.  
  52.  3     5
  53.  
  54. >> mean_matrix_valid =
  55.  
  56.     1.0000    2.0000    3.5000    3.5000    3.5000
  57.     2.0000    2.0000    2.5000    2.5000    2.5000
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top