How to do this function
Show older comments
Hi to all! I'm from Italy and i'm new to this forum! I need some help in writing this function in Matlab. I have to vectors X and Y. For example X=[1,2,0,2,1] and Y=[2,3,-1,0,1,0,0]. I consider two sets, S_X and S_Y, composed by the distinct elements of my two vectors. In the example S_X={0,1,2} and S_Y={-1,0,1,2,3}. Now, i need a function that have to have in input two vectors X and Y and in output a variable W defined like these:
W= -1 if S_X is contained in S_Y, but S_X and S_Y are different W= 1 if S_Y is contained in S_X, but S_X and S_Y are different W= 0 if S_X=S_Y W= Nan otherwise
Thanks a lot Bye Vito
2 Comments
Jan
on 16 Jul 2012
Because this is a homework question, I recommend the standard procedure: Please post, what you have tried so far and which problems occurred. A forum should not solve your homework, otherwise your professor will not recommend this forum any longer.
Answers (1)
Sean de Wolski
on 16 Jul 2012
doc unique
doc ismember
doc setdiff
doc setxor
doc intersect
etc...
6 Comments
Vito
on 16 Jul 2012
Matt Kindig
on 16 Jul 2012
Well the natural follow-up questions is what built-in functions can you use? Can you use "find"? "for" loops? "if-else" statements? "sort"?. You can do what you want to do using those functions.
Ryan
on 16 Jul 2012
To me the natural follow-up question is did you actually learn the approach to solve these problems?
Vito
on 16 Jul 2012
Vito
on 16 Jul 2012
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!