Exclude an element from a vector

1 回表示 (過去 30 日間)
daniel
daniel 2013 年 11 月 5 日
回答済み: daniel 2013 年 11 月 5 日
I have a vector z which gets elements from another vector c. vector c is a random sample which creates a 5 element vector. I want to know how to exclude an element in vector z which appears twice or more in vector c. By the way , my lecturer does not want us to use matlab functions! The code:
function table=calcAllPercentages(sample)
%get the length of the sample
c=length(sample);
%z is a vector for the relevent sample elements , this operation
%is for getting rid of elements that apper more then once.
z=[];
for i=1:c
if length(z)==0
z=sample(i);
else
for j=1:length(z)
if sample(i)~=z(j) && j==length(z)
z(length(z)+1)=sample(i);
else sample(i)== z(j);
  1 件のコメント
Image Analyst
Image Analyst 2013 年 11 月 5 日
Are these integers, floating point numbers, or characters or something else?

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

回答 (2 件)

Walter Roberson
Walter Roberson 2013 年 11 月 5 日

daniel
daniel 2013 年 11 月 5 日
Thanks for the help! I got it!

カテゴリ

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