Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

MTR09
Lv 4
MTR09 asked in Science & MathematicsEngineering · 10 years ago

How do you state two conditions for an "if" statement in MATLAB?

I'm completely new to MATLAB and I am writing a function to find diagonal dominance in square matrices of unknown dimensions.

I am calling the matrix "A", then using B=abs(A) to get all the components as positive and C=length(A) to identify the dimensions (I already have programmed the error messages if A isn't square).

My idea is to say "i=1" and then use;

if 2*B(i,i)=>B(i,:)

ddom=1;

else ddom=0;

My idea is then to say that if both i=<C and if ddom=1, i=i+1.

I'm pretty sure my reasoning is fairly sound, but I don't know how to use an "if" statement that is dependant on two conditions.

If anyone could help it'd be really appreciated.

5 Answers

Relevance
  • Anonymous
    10 years ago
    Favorite Answer

    Hey dude,

    Here is what you can do,

    if ((i<=C)&&(ddom=1))

    i=i+1;

    end

    The above implies that if the two conditions occur in conjunction, the increment takes place. But if any of them or none is true, MATLAB will skip the increment and continues executing what comes after the if-statement.

    Good luck

  • ?
    Lv 4
    4 years ago

    Or Statement Matlab

  • 5 years ago

    Octave If Statement

  • Anonymous
    5 years ago

    For the best answers, search on this site https://shorturl.im/av7WH

    1. "Democartic" governments work to improve conditions by forcing children to do their own homework. If cheating occurs, the punishment is death. 2. "Democartic" governments work to improve their societies by weeding out cheaters early in life. You're welcome!

  • How do you think about the answers? You can sign in to vote the answer.
  • and or statements. if blah and blah equals, less than, greater than, then blah blah. If blah or blah equals, less than, greater than, then blah blah.

Still have questions? Get your answers by asking now.