Results 1 to 4 of 4

Math Help - Matlab logical operators

  1. #1
    Newbie
    Joined
    Dec 2008
    Posts
    5

    Matlab logical operators

    Hey,
    I'm doing a model in matlab and for some reason the following logical statement will not produce what it is meant to produce.
    The structure is the following:
    initial values
    for loop(j=1:1:10)
    while loop(
    while
    G>e
    i=i+1
    ...
    AB(i)=j+...
    G=abs(AB(i+1)-AB(i))
    )
    if staement (
    if
    (AB(i)<1)
    AB
    end
    )
    hope you got the point.
    the trouble is that it prints all of the values of AB to the screen( for all the i's)-including AB=1.
    what's wrong with it? I can't figure it out.
    Any help would be most appreciated.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Rorshach View Post
    Hey,
    I'm doing a model in matlab and for some reason the following logical statement will not produce what it is meant to produce.
    The structure is the following:
    initial values
    for loop(j=1:1:10)
    while loop(
    while
    G>e
    i=i+1
    ...
    AB(i)=j+...
    G=abs(AB(i+1)-AB(i))
    )
    if staement (
    if
    (AB(i)<1)
    AB
    end
    )
    hope you got the point.
    the trouble is that it prints all of the values of AB to the screen( for all the i's)-including AB=1.
    what's wrong with it? I can't figure it out.
    Any help would be most appreciated.
    Well I don't recognise most of that as being in Matlab syntax.

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Dec 2008
    Posts
    5

    thanks,but:

    I'ts just a discription of the code, I need some general advice about how to make it work and how the logical opertators work.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Member
    Joined
    Jan 2009
    Posts
    153
    This is a demo.
    How to print elements by specified condition

    AB = 2*rand(1, 10); % generating random elements
    idx = []; % store index of selected elements

    for i=1:10
    if AB(i) > 1
    idx = [idx i];
    end;
    end;

    AB(idx) % display selected elements.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Operators
    Posted in the Differential Equations Forum
    Replies: 1
    Last Post: December 5th 2010, 08:18 PM
  2. Example of operators
    Posted in the Differential Geometry Forum
    Replies: 3
    Last Post: October 10th 2010, 12:32 PM
  3. Prove/disprove using logical using logical arguments
    Posted in the Discrete Math Forum
    Replies: 5
    Last Post: February 24th 2010, 07:29 AM
  4. Replies: 3
    Last Post: January 21st 2010, 08:45 AM
  5. Unbounded Operators
    Posted in the Differential Geometry Forum
    Replies: 6
    Last Post: March 22nd 2009, 02:01 PM

Search Tags


/mathhelpforum @mathhelpforum