How to explore off diagonal elements in matrices without avoiding the for loop?
이전 댓글 표시
I need to search if the value of off diagonal elements of many matrices are larger than a specific number. Was wondering if I can do that without using a loop.
댓글 수: 1
James Tursa
2020년 4월 15일
Square matrices? Just the nearest off-diagonals?
답변 (2개)
Peng Li
2020년 4월 15일
0 개 추천
Not sure if many matrices share the same size. Anyway if you store these matrices in a cell you prob have a chance using cellfun to accomplish this I think. You can use triu or tril to get all off diagonal elements.
Vasilis Chasiotis
2020년 10월 8일
편집: Vasilis Chasiotis
2020년 10월 8일
A = randn(n,n); % a n-by-n matrix of random numbers
idx = eye(n,n); % the identity matrix of order n
if all( A(~idx) > K ) % check if all the off-diagonal elements of A are greater than K
...
end
So, you check all the off-diagonal elements of A without using a loop.
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!