code without using for

조회 수: 5 (최근 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.
huda nawaf
huda nawaf 2013년 3월 17일
many thanks

댓글을 달려면 로그인하십시오.

채택된 답변

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
huda nawaf
huda nawaf 2013년 3월 17일
many thanks

댓글을 달려면 로그인하십시오.

추가 답변 (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.
  댓글 수: 1
huda nawaf
huda nawaf 2013년 3월 17일
many thanks

댓글을 달려면 로그인하십시오.

카테고리

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