필터 지우기
필터 지우기

how to get the value of two variables with respect to fixed value.

조회 수: 2 (최근 30일)
jaah navi
jaah navi 2019년 4월 12일
댓글: KSSV 2019년 4월 15일
could anyone help me how to get the values of two variables A and B under the condition A<B,such that the sum of A and B should be (10,20,30,40,50).

채택된 답변

KSSV
KSSV 2019년 4월 12일
A = 0:50 ;
B = 0:50 ;
S = [10 20 30 40 50] ;
[A,B] = meshgrid(A,B) ;
A(A>B) = NaN ;
C = A+B ;
% Get A<B but A+B = 10
idx = find(C==10) ;
[A(idx) B(idx) A(idx)+B(idx)]
  댓글 수: 10
jaah navi
jaah navi 2019년 4월 13일
with respect to the code given by you
A = 0:50 ;
B = 0:50 ;
S = [10 20 30 40 50] ;
[A,B] = meshgrid(A,B) ;
A(A>B) = NaN ;
C = A+B ;
% Get A<B but A+B = 10
idx = find(C==10) ;
[A(idx) B(idx) A(idx)+B(idx)]
It works for round values.
But it doesnot work for decimal vaues
for example[10.5 20.6 30 .6 40.4 50.5]
could you help me how to do it for decimal values.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by