Help me with this problem
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to extract the column and row values if they meet this below condition.I have tried it in two ways
for i=1:4
for j=1:4
if(A(i,j)~=0 && B(i,j)<=5)
Arraylow=j; %Error- getting A={1,0,3,0}
elseif
ArrayHigh=j;
end
end
Expected Output:Array: {1,1,1,2,2,1,2,2}={1,2}
for 1st row-(1,1),(1,2)
2ndrow-(2,1)(2,2)
3rdrow-nil
4th row-nil
A matrix(4*4):
1 2 0 0
2 1 2 0
0 2 1 2
0 0 2 1
B matrix:
0 5 34 22
5 0 34 21
34 34 0 10
22 21 10 0
댓글 수: 0
채택된 답변
Matthew Eicholtz
2017년 5월 5일
I don't think you need the for-loops here. Try this:
A = [1 2 0 0; 2 1 2 0; 0 2 1 2; 0 0 2 1];
B = [0 5 34 22; 5 0 34 21; 34 34 0 10; 22 21 10 0];
mask = (A~=0) & (B<=5);
If you need to know the rows and columns that meet the criteria, use find:
[rows,cols] = find(mask);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!