Help me with this problem

조회 수: 1 (최근 30일)
Ad
Ad 2017년 5월 5일
답변: Matthew Eicholtz 2017년 5월 5일
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

채택된 답변

Matthew Eicholtz
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개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by