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 Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by