Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

code without using for

Asked by huda nawaf

huda nawaf (view profile)

on 17 Mar 2013

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 Comments

the cyclist

the cyclist (view profile)

on 17 Mar 2013

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 (view profile)

on 17 Mar 2013

many thanks

huda nawaf

huda nawaf (view profile)

Tags

Products

No products are associated with this question.

2 Answers

Answer by Cedric Wannaz

Cedric Wannaz (view profile)

on 17 Mar 2013
Accepted answer

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 Comment

huda nawaf

huda nawaf (view profile)

on 17 Mar 2013

many thanks

Cedric Wannaz

Cedric Wannaz (view profile)

Answer by Walter Roberson

Walter Roberson (view profile)

on 17 Mar 2013
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 Comment

huda nawaf

huda nawaf (view profile)

on 17 Mar 2013

many thanks

Walter Roberson

Walter Roberson (view profile)

Contact us