Create a new vector with the elements of another vector

10 ビュー (過去 30 日間)
Tim
Tim 2014 年 10 月 22 日
コメント済み: Star Strider 2014 年 10 月 22 日
I have 2 vectors
a=[5 1 9 7 0 -5 1 -2]
b=[2 8 1 6 -8 -3 4 1] I need to create a vector c, which is made up of elements of b that are greater than a.
My attempt:
c=b(b>a)
c= 8 4 1
I don't know if I understand the question or it is that easy. Please help me!

採用された回答

Star Strider
Star Strider 2014 年 10 月 22 日
It could be that easy, depending on how the question was phrased and what it wants you to do. From the documentation on Relational Operators < > <= >= == ~=
  • ‘The relational operators are <, >, <=, >=, ==, and ~=. Relational operators perform element-by-element comparisons between two arrays.’
(I got c = [8 -3 4 1] so I assume you left out -3.)

その他の回答 (1 件)

Tim
Tim 2014 年 10 月 22 日
Yes, I left out -3. I was just making two random vectors and wrote the script without trying running it on matlab :) Thank you very much.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by