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

Thread Subject:
summing prime number in vector

Subject: summing prime number in vector

From: James

Date: 4 Feb, 2012 02:39:22

Message: 1 of 2

What i have to do is write a function that checks to see if vector x size is greater then 2 then compute the sum of all the prime number in the vectors. This is what i have so far:

function y = fun(x)
if size(x)>2
    total=0;
    for x
        if((isprime(x))
            total=total+x;
        end
    end
end

I am not sure what i did wrong can anyone help me out thanks.

Subject: summing prime number in vector

From: John D'Errico

Date: 4 Feb, 2012 03:05:31

Message: 2 of 2

"James " <tothe1234@yahoo.com> wrote in message <jgi5oq$pst$1@newscl01ah.mathworks.com>...
> What i have to do is write a function that checks to see if vector x size is greater then 2 then compute the sum of all the prime number in the vectors. This is what i have so far:
>
> function y = fun(x)
> if size(x)>2
> total=0;
> for x
> if((isprime(x))
> total=total+x;
> end
> end
> end
>
> I am not sure what i did wrong can anyone help me out thanks.

I would start with

help for

John

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us