Decrease the least and increase the highest

10 ビュー (過去 30 日間)
sasso samer
sasso samer 2016 年 7 月 21 日
コメント済み: Star Strider 2016 年 7 月 21 日
I have an array
A = [1 -3 -6 10 2 3 7 -1 -9 -3]
B = [1 2 3 4 5 6 7 8 9 10]
1) I want to check the least negative and the highest positive in array A.
2) In the corresponding number in Matrix B, if it is the least negative then multiply the number in B by 10 and if it is the highest positive, then multiply the number in B by 100.
3) Then B = [1 2 3 400 5 6 7 8 90 10]
  2 件のコメント
Image Analyst
Image Analyst 2016 年 7 月 21 日
Are you sure that's what they want? It's kind of ambiguous. You could also assert that the least negative value is the -1, and the most negative value is -9, in which case the 8 would be multiplied by 10 instead of the 9.
Star Strider
Star Strider 2016 年 7 月 21 日
OP seems to be posting homework problems.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2016 年 7 月 21 日
A = [1 -3 -6 10 2 3 7 -1 -9 -3];
B = [1 2 3 4 5 6 7 8 9 10];
[~,idxlo] = min(A);
[~,idxhi] = max(A);
B(idxlo) = 10*B(idxlo);
B(idxhi) = 100*B(idxhi)
B =
1 2 3 400 5 6 7 8 90 10

その他の回答 (1 件)

Thorsten
Thorsten 2016 年 7 月 21 日
編集済み: Thorsten 2016 年 7 月 21 日
B(A == max(A)) = B(A == max(A))*100;
B(A == min(A)) = B(A == min(A))*10;

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by