Help me with this problem

1 vue (au cours des 30 derniers jours)
Ad
Ad le 5 Mai 2017
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

Réponse acceptée

Matthew Eicholtz
Matthew Eicholtz le 5 Mai 2017
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);

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by