How to do this function

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 件のコメント

Jan
Jan 2012 年 7 月 16 日
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.
Vito
Vito 2012 年 7 月 16 日
編集済み: Vito 2012 年 7 月 16 日
Thanks Jan Simon for the answer. I had not posted my "solution" just becouse it is so short and not really complete. I've just thinked to do
m==size(x) n==size(y) for i=1:m for j=1:n if x(i)!=x(j)....S_x={...}
else S_y={...}
After i really don't know how to write it better in Matlab and how to continue this solution.
Hope you understand me.
Bye Vito.

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

回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 7 月 16 日

1 投票

doc unique
doc ismember
doc setdiff
doc setxor
doc intersect
etc...

6 件のコメント

Vito
Vito 2012 年 7 月 16 日
Thanks for the answer Sean de Wolski, but my professors don't want i'm gonna use this "pre-definined" function. I think they want to show them i've learned the approach to solve these problems. There is another way more explicative to solve my problem? Thanks a lot Vito
Matt Kindig
Matt Kindig 2012 年 7 月 16 日
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.
Sean de Wolski
Sean de Wolski 2012 年 7 月 16 日
Ryan
Ryan 2012 年 7 月 16 日
To me the natural follow-up question is did you actually learn the approach to solve these problems?
Vito
Vito 2012 年 7 月 16 日
Thanks for your answer Ryan. The course my professor have done was for me so incompolete and i'm not actually in condition to solve this problems. I just hope i'll find an help in this forum. Bye Vito
Vito
Vito 2012 年 7 月 16 日
Thanks Matt for your answer i can use "for" loops and "if-else" statements!

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

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2012 年 7 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by