How to find indices of value that are greater than zero and less than 5
    조회 수: 36 (최근 30일)
  
       이전 댓글 표시
    
I want to find the indices of a matrix and I am using this command.
if true
  nhd = find(dist_mat1>0 & dist_mat1<6);
end
It is giving me a single column matrix. Is it possible that it can find the indices of all elements from first row, then second and then third. so that I have output variable index has three rows and each value in row shows the column number only.
like nhd = [1,3,4,7;1,2,3,6,7;1,4]
Is it possible ?

댓글 수: 0
채택된 답변
  Star Strider
      
      
 2016년 2월 15일
        This works:
dist_mat1 = randi([0 7], 3, 7);                     % Create Matrix
[RowNrs,ColNrs] = find(dist_mat1>0 & dist_mat1<6);
[RowNrSort, Idx] = sort(RowNrs);
for k1 = 1:max(RowNrs)
    Out{k1} = ColNrs(Idx(RowNrSort == k1));
end
댓글 수: 4
  Star Strider
      
      
 2016년 2월 15일
				I am not quite certain what you want to do.
The unique function — possibly with more than one output — could be an option.
  Image Analyst
      
      
 2016년 2월 16일
				If they're all integers, maybe take the histogram and find the bin where the count is the number of arrays you examined, which would mean that number was in each of the arrays you examined.
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


