필터 지우기
필터 지우기

Conditional in values of a matrix

조회 수: 18 (최근 30일)
Montserrat Vallcorba Martí
Montserrat Vallcorba Martí 2017년 11월 30일
댓글: Star Strider 2017년 12월 1일
Hi,
I want to do the following condition in a matrix:
The example:
Any suggestion?
Thank you!

채택된 답변

KL
KL 2017년 11월 30일
indx = A(:,2)<0;
B = indx.*A(:,2) + ~indx.*(A(:,2)-A(:,3).*abs(A(:,2)))

추가 답변 (1개)

Star Strider
Star Strider 2017년 11월 30일
Your original description of the problem contains an error.
In order to get ‘Vector B’, you need to divide ‘abs(A(i,3))’ by 100.
This works, and gives the correct result:
A = [0.08 -0.335 75; 0.017 -0.335 75; 7.17 0.468 38.5; 19.33 1.379 29; 150 3.73 20];
B = A(:,2)-A(:,3).*abs(A(:,2))/100;
B(A(:,2)<0) = A(A(:,2)<0,2)
B =
-0.3350
-0.3350
0.2878
0.9791
2.9840
  댓글 수: 2
Montserrat Vallcorba Martí
Montserrat Vallcorba Martí 2017년 12월 1일
Thank you!
Star Strider
Star Strider 2017년 12월 1일
My pleasure!

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by