Need help writing an if statement involving vectors. Total mental block :/
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Trevor Zane Simko
am 5 Mai 2015
Kommentiert: Star Strider
am 5 Mai 2015
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 Kommentare
Akzeptierte Antwort
Charlie Elverson
am 5 Mai 2015
Bearbeitet: Charlie Elverson
am 5 Mai 2015
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!