How can I transfer values if specific condition is fulfilled?

조회 수: 2 (최근 30일)
Max Behr
Max Behr 2020년 4월 22일
댓글: Ameer Hamza 2020년 4월 22일
Hello,
I got a Matrix with different cases:
a= (6,6)
0 1 0 2 0 0
0 2 0 1 0 0
0 1 0 2 0 0
0 1 0 2 0 0
0 1 0 2 0 0
0 2 0 1 0 0
And another matrix with different values:
b=(6,6)
1 3 1 1 3 1
2 4 2 3 4 3
3 5 3 4 5 4
4 6 3 5 6 5
5 5 4 6 5 6
6 6 5 6 6 6
Now I would like to transfer values of second and fourth collum of b [b(x,2)&b(x,4)] into a new Matrix if condition a(x,2) or a(x,4)= 1 is fulfilled.
So the end result would look like this:
c=(6,1)
3
3
5
6
5
6
How can I do this with Matlab? And I would like to keep the order. So it should work from line to line. Not collum for collum.
Thanks for helping me.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 22일
편집: Ameer Hamza 2020년 4월 22일
A = a.';
B = b.';
B(A==1)
  댓글 수: 4
Max Behr
Max Behr 2020년 4월 22일
Perfect, it works ! Thanks a lot :)
Ameer Hamza
Ameer Hamza 2020년 4월 22일
Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by