code without using for

1 次查看(过去 30 天)
huda nawaf
huda nawaf 2013-3-17
hi,
I want code do the following without using for,if let unique_x is a vector
t=1;
for v=1:length(z)
a1=find(unique_x==z(v));
if isempty(a1)
evaluation(t)=z(v);
t=t+1;
end
end
thanks in advance
  2 个评论
the cyclist
the cyclist 2013-3-17
It would be easier for us to help you if you supplied a small example of self-contained code that runs from start to finish. Specifically, telling us a small example of unique_x and z would help.

请先登录,再进行评论。

采纳的回答

Cedric
Cedric 2013-3-17
I think that you'll want something along the line of the following example:
>> z = [3 5 7] ;
>> unique_x = [1 2 7 8 9 3] ;
>> evaluation = z(~ismember(z, unique_x))
evaluation =
5

更多回答(1 个)

Walter Roberson
Walter Roberson 2013-3-17
setdiff(z, unique_x)
provided that you do not care about the order of the results, and there are no duplicate values in z.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by