Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of MATLAB
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Related Books

Bookmark and Share
Lecture Comments (4)

0 answers

Post by Joshua Bowen on May 20, 2015

Can I import multiple arrays to a Variable? if so how?

0 answers

Post by Joshua Bowen on May 20, 2015

Hello,

I have created a random number generator of 5 numbers between 1-78 (without) and bonus number between 1-15.... but each time I run it I want all six numbers to be as one array of numbers, how do I do this...then I have previous numbers that I want to import into matlab into Matlab, if my random generator generates one of those numbers I imported it starts over...
What is the best approach to doing this?

1 answer

Last reply by: Professor Arash Vafanejad
Thu Feb 27, 2014 6:08 PM

Post by Nicholas Lasky on February 24, 2014

I need to find if a vector h = [1 3 6 -7 -45 12 17 9] satisfy h > a and h < b   a = 3 and b = 13  the result will return a vector with answers 0 or 1 depending on if the statement is satisfied
thus far i have written:
h = [1 3 6 -7 -45 12 17 9];
>> a = 3;
>> b = 13;
>> if h > a && h < b
     v = 0;
  else
     v = 1;
  end
  disp(v)
Operands to the || and && operators must be convertible to logical scalar values.
not sure what im doing wrong

Decisions, Part 1

  • if: the if construct, which is fundamental to all computing languages, is the basis for a decision making. The simple form of if in a single line is:
  • if condition statement, end
  • Note that conditions are usually a logical expression, which are either true or false. If condition is true, statement is executed, otherwise nothing happens. Condition maybe a vector or matrix, in which case it is true if all its elements are non-zero.
  • The basic if-else form is:
    • if condition
    • statements A
    • else
    • statements B
    • end
  • On the other hand we can have elseif and use it like a ladder:
    • if condition1
    • statementsA
    • elseif condition2
    • statementsB
    • elseif condition3
    • statementsC
    • ...
    • else
    • statementsE
    • end

Decisions, Part 1

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • If Function 0:13
    • Rand
    • Meaning of “1” and “0”
  • If-Else Construct 3:48
  • Elseif 8:43
    • Using Elseif
  • Logical Operators 12:13
    • &, |, ~