This site is 100% ad supported. Please add an exception to adblock for this site.

CS 1371 final

Terms

undefined, object
copy deck

VECTORS:

DIRECT ENTRY 

Input values of the vector directly.

 ex: vec = [1 2 3]

VECTORS:

COLON OPERATOR INPUT 

Input values into a vector by giving a range of values. Default steps is 1.

 ex: vec = 1:3

            = [1 2 3]

 ex: backwards: vec = 3:-1:1

     

VECTORS:

 INDEXING

Removes values specified by index.

ex: vec = [5 3 1 7 8 2 9]

      vec([2, 4, 6])

        = [3 7 2]

Can also erase values in a vector

ex: vec([2, 4, 6]) = []

&

VECTOR OPERATIONS

 RANDOM NUMBER GENERATOR IN VECTOR

rand(#R, #C)

        -gives random numbers between 0 and 1

        -to change range of rand--> 

        ex: random #s from 8-10

 

VECTOR OPERATIONS

      OTHERS

   

    ones(#R, #C) => gives a vector of 1s

    zeros(#R, #C) => gives a vector of 0s

    linspace(start, stop, # of elements) => gives 

  &nb

DATA TYPES

"char" = characters/strings. ex: 'abc'

"doubles" = numbers/numerical vectors. ex: 2, [1 2 3]

"cell" = cell arrays. ex: {'abc'} {5}

"logical" = true or false, 1 or 0&

CELL ARRAYS

    ACCESSING DATA IN ARRAY

ca{row,col}

or

ca{row,col}(3) <= used if trying to find certain value in a vector that was part of a ca

 ex: ca = {'a', [1 3]; 'c', 4}

        to access the number 3:

CELL ARRAYS

    DATA INPUT

v = {'a',[1 3];'c', 4}

or

v = [{'a'}, {[1 3]}; {'c'}, {4}] 

STRUCTURES

    CREATING STRUCTURES: DIRECT 

     

student.name = 'Michael'

student.age = 20

student.major = Mechanical Engineering

student

    = name: Michael

       age: 20

       major: Mech

STRUCTURES

    CREATING STRUCTURES: USING STRUCT() FUNCTION 

student = struct('name', 'Michael', 'age', 20, 'major', 'Mechanical Engineering')

STRUCTURES

    FIELD OPERATOR FUNCTIONS 

 setfield() => adds or changes a field

    ex: newStruct = setfield(myStruct, 'housing',       'Glenn') 

 getfield(structure, field)

 rmfield(structure, fi

FUNCTIONS

    VALID FUNCTION HEADERS 

function [out1, out2] = name(in1,in2)

function [] = name(in1, in2)

function name(inputs)

function output = name(inputs) 

CONDITIONALS

if/switch statements

 switch x

    case 5

        out = 'no'

    case 3

        out = 'yes'

  &

ITTERATION

for/while loops

 -while loops move toward a terminating condition

    ex: vec = 1:10

          counter = 1

          while(vec(counter)<

RECURSION

similar to while loops

trace function

3 conditions for recursion function

    -must call a clone of itself

    -must have a terminating condition

    -must move toward terminati

FILE I/O

    LOWER LEVEL FUNCTIONS

fopen - file open

fclose - file close 

fgets - gets entire line including delimitor

fgetm - does not includ delimitors

fprintf - prints file data

FILE I/O

    HIGHER LEVEL FUNCTIONS 

[num txt raw] = xlsread(filename)

xlswrite

csvread

dlmread 

PLOTTING

plot(x,y)

xlabel('name') or xlabel name

title('name')

subplot(R,C,subplot#)

ex:

subplot(2,2,1)

plot(x,y) 

1 2

3 4 

will plot graph in 1st subplot 

BODIES OF ROTATION

    CODING 

Take function: y = x^(1/2)

y = v  and  x = u

u = 0:100

v = sqrt(u)

th = linspace(0, 2*pi)

[uu tth] = meshgrid(u, th)

[vv tth] = meshgrid(v, th)

rr = uu

yy = vv

zz = rr.*sin(tth)

xx =

Deck Info

19

squeegeee

permalink