필터 지우기
필터 지우기

Question of Comparing two vectors

조회 수: 1 (최근 30일)
mingcheng nie
mingcheng nie 2022년 11월 5일
답변: Matt J 2022년 11월 5일
Hi there,
If we consider two vector a and b, they have the equal length and random generate from [-2,2]. Now I want to compare their each entry with each other, i.e., a(i) compare with b(i) and set the result as c(i), I want to find the maximum one between a(i) and b(i), with extra condition: I only want the valur within [0,1], i.e., if a(i)=0.5 and b(i)=1.5, as b(i) is greater than 1, then c(i) will be 0.5; but if a(i)=0.5 and b(i)=0.7, then c(i)=0.7.
Is there any efficiency way to perform this?
Thanks,
Charlie
  댓글 수: 1
dpb
dpb 2022년 11월 5일
  1. If [-2,2] is range, what about all those <0 in a,b? Are they excluded from c?
  2. If both a,b >1 or <0?

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

채택된 답변

Matt J
Matt J 2022년 11월 5일
a(a<0 | a>1)=nan;
b(b<0 | b>1)=nan;
c=max(a,b);

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by