How can already used elements be eliminated one by one in 2D matrix while moving upwards? | Efficienlty
    3 次查看(过去 30 天)
  
       显示 更早的评论
    
Input
input = [1 2 0;
         2 3 4;
         4 5 6];
Output
Output= [1 0 0;
         2 3 0;
         4 5 6];
Why efficiently : For inputting a big matrix of say 360000 x 36.
0 个评论
采纳的回答
  James Tursa
      
      
 2018-11-3
        
      编辑:James Tursa
      
      
 2018-11-3
  
      r = rot90(inputMatrix,-1); % turn rows into columns with last row as first column
[~,ix] = unique(r); % get the unique linear indexing with preference to leftmost columns
result = zeros(size(r)); % initialize result as all 0's
result(ix) = r(ix); % fill in the unique values with preference to leftmost columns
result = rot90(result); % rotate back to original orientation
更多回答(1 个)
  Image Analyst
      
      
 2018-11-3
        Use unique():
inputMatrix = [1 2 0;
  2 3 4;
  4 5 6]
[~, ia, ic] = unique(inputMatrix);
output = zeros(size(inputMatrix)); % Initialize
output(ia) = inputMatrix(ia)
4 个评论
  Walter Roberson
      
      
 2018-11-3
				That output contradicts the original pattern. For that "should be" output to be true, then the output for
input = [1 2 0;
         2 3 4;
         4 5 6];
should be
[1 2 0;
 3 4 0;
 5 6 0;]
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



