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

采纳的回答

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