Got Questions? Get Answers.
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:
Problem with If any condition Help!

Subject: Problem with If any condition Help!

From: Juana

Date: 21 Aug, 2012 03:02:07

Message: 1 of 3

I´m running this code and it's working but, I have a huge problem in the condition if any (p(h)>=300) because the upcoming vector is showing numbers over 300 I can't understand what's wrong. can anybody help me?

for i=0:inf
    h=i+1;
     p(h)=170*(sqrt(h/4)
     pp=p
     
     
if any (p(h)>=300)
    break
    else
      continue
end
 
 end

Subject: Problem with If any condition Help!

From: TideMan

Date: 21 Aug, 2012 03:33:36

Message: 2 of 3

On Tuesday, August 21, 2012 3:02:07 PM UTC+12, Juana wrote:
> Im running this code and it's working but, I have a huge problem in the condition if any (p(h)>=300) because the upcoming vector is showing numbers over 300 I can't understand what's wrong. can anybody help me?
>
>
>
> for i=0:inf
>
> h=i+1;
>
> p(h)=170*(sqrt(h/4)
>
> pp=p
>
>
>
>
>
> if any (p(h)>=300)
>
> break
>
> else
>
> continue
>
> end
>
>
>
> end

No if, no loop required:
hmx=fix((300/170)^2*4);
h=1:hmx;
p=170*sqrt(h/4);

Subject: Problem with If any condition Help!

From: Torsten

Date: 21 Aug, 2012 06:16:42

Message: 3 of 3

On 21 Aug., 05:02, "Juana " <mariac_bl...@hotmail.com> wrote:
> Im running this code and it's working but, I have a huge problem in the condition if any (p(h)>=300) because the upcoming vector is showing numbers over 300 I can't understand what's wrong. can anybody help me?
>
> for i=0:inf
> h=i+1;
> p(h)=170*(sqrt(h/4)
> pp=p
>
> if any (p(h)>=300)
> break
> else
> continue
> end
>
> end

If you want to check whether there is at least one element in the
vector p
the value of which is greater or equal to 300, use
if any(p(:)>=300) ;
if you want to check whether element h of the vector p is greater or
equal to 300, use
if p(h)>=300

Best wishes
Torsten.

Tags for 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