Mulitply diffrent numbers in a vector by a corrsponding number.

조회 수: 3 (최근 30일)
jason
jason 2022년 9월 7일
답변: Walter Roberson 2022년 9월 7일
I have to multiply a specific number in a vector by different scalars. For example, in the vector: [1 6 8 10 14 20 25] 1,2,8 and 10 would be multiplied by 10, while 14, 20, and 25 would be multiplied by different scalars.
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 9월 7일
Are they to be multiplied based upon value, or based upon position?
If it is based upon value, then are the boundaries based upon range, or are they scattered around?

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

답변 (2개)

David Hill
David Hill 2022년 9월 7일
v=[1 6 8 10 14 20 25];
v(ismember(v,[1 2 8 10]))=10*v(ismember(v,[1 2 8 10]));%similarly for others

Walter Roberson
Walter Roberson 2022년 9월 7일
V = [1 6 8 10 14 20 25]
V = 1×7
1 6 8 10 14 20 25
mask = V <= 10;
V(mask) = V(mask) * 10;
V(~mask) = V(~mask) * 100;
V
V = 1×7
10 60 80 100 1400 2000 2500

카테고리

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

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by