フィルターのクリア

Need help writing an if statement involving vectors. Total mental block :/

2 ビュー (過去 30 日間)
Trevor Zane Simko
Trevor Zane Simko 2015 年 5 月 5 日
コメント済み: Star Strider 2015 年 5 月 5 日
I have a vector:
A=[14 13 12 11 10]
And I'm given another vector B that's the same length of A, and contains any numbers.
I need to write an if statement determining if this vector B contains the same numbers as A (even if the numbers are arranged differently than in A)
NOTE: INCORRECT SYNTAX, but here's the idea
if B==A
disp('B is equal to A')
else
end
  3 件のコメント
Trevor Zane Simko
Trevor Zane Simko 2015 年 5 月 5 日
Ok thanks. I appreciate your help anyways.
Star Strider
Star Strider 2015 年 5 月 5 日
My pleasure. It’s not the first time I misinterpreted a Question!

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

採用された回答

Charlie Elverson
Charlie Elverson 2015 年 5 月 5 日
編集済み: Charlie Elverson 2015 年 5 月 5 日
I think you could use the ismember() function to do what you need. It'll return a vector of ones and zeros, so you would just have to check the returned vector for any zeros.
EDIT: if you use all(ismember(A, B)), I think that'll do the trick.
  3 件のコメント
Trevor Zane Simko
Trevor Zane Simko 2015 年 5 月 5 日
Works Perfectly! Thank you! I've got one more problem for you, if you're up for it :) This one is probably a bit more tricky.
Star Strider
Star Strider 2015 年 5 月 5 日
A new problem is best posed as a new question.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by