matlab Flashcards

1
Q

What are variables?

A

Variables are memory stored within the hardware of computers and are used to store data that can be either strings or numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the rules for creating variable names in MATLAB?

A
  1. Variables must start with a non-numerical character
  2. Variable names can include lowercase, uppercase, numbers and underscores
  3. Variable names cannot exceed a certain length (differs for different computer systems)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the assignment operator do in MATLAB?

A

Stores a variable under a variable name by changing the memory in the computer (assigns a new value to the location in the computer)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do operators do?

A

Operators manipulate data by taking data values as input and either:
1. producing some output value
2. changing the memory of the machine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What functions can be used to output messages?

A
  1. disp – e.g. disp(“Hello world”);
    -to display multiple things, disp([variable1, variable2]);
  2. fprintf – e.g. fprintf(“Hello world”);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the syntax for taking string inputs from the user?

A

variableName = input(“string”, “s”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the process of programming?

A

To automate a computational process by transforming data in a computer’s memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are examples of operations?

A
  1. A computer’s memory
  2. Multiplication
  3. Addition
  4. Assignment
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What parts make up a variable?

A
  1. Name
  2. Data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is computer memory?

A

A long sequence of locations where data can be stored

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are vectors?

A

1-dimensional data structure for grouping multiple pieces of data (an nx1 matrix).
-Use square brackets to assign elements
e.g vector = [1 2 3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are columns and rows?

A

Columns go across, rows go down

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When to use a for-loop instead of a while loop?

A

For loops are used when the number of repetitions for code is known, e.g. wanting to loop to roll a dice 6 times.
While loops are used when the number of loops required is unknown, e.g. rolling a dice until an even number is rolled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the for-loop syntax?

A

for i = 1:n – from 1 to n times
for i = 1:0.5:n – from 1 to n in 0.5 increments
for i = n:-1:1 – from n to one in increments of 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to access elements in a vector?

A

Use roundbrackets – MATLAB element numbering starts at 1
e.g. vector = [1 2 3]
vector(1) = 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is concatenation?

A

The process of joining 2 or more parts (vectors) together

17
Q

How are vectors in MATLAB stored?

A

Vectors are automatically flattened when containing nested vectors
e.g. [ [1] [2] ] –> [1 2]

18
Q

What is appending?

A

Adding data to the end of existing data

19
Q

What is prepending?

A

Adding data before a piece of existing data

20
Q

What is the syntax for using the zeros command?

A

variableName = zeros(rows, columns)

21
Q

What is the difference between using “string” and ‘string’?

A

“String” stores the entire word as an element, whereas ‘string’ stores each individual letter as an element.

e.g string = [“String” “Low” “Me”]
string(3) = “Me”
string = [‘String’ ‘Low’ ‘Me]
string(3) = ‘r’

22
Q

What are some built in string functions in MATLAB?

A
  1. upper(a) - converts a to uppercase
  2. lower(a) - converts a to lowercase
  3. findstr(date, ‘/’) - searches for ‘/’ in date
  4. strcmp(test, ‘apple’) - compares test to apple
    strtrim(‘North Terrace’) - removes leading and trailing spaces from ‘North Terrace’
23
Q

How to make 2D arrays?

A

Use ‘;’ between elements when a new row is being made – each row has to have same number of elements

24
Q

How would we iterate over each element in a 2D array?

A

By using a nested loop - the outer loop iterates over the rows while the inner loop iterates over the columns

25
Q

What is the default class for storing image data in MATLAB?

A

The default is uint8, as it is more compact

26
Q

What are the differences between uint8 and double?

A

uint8 takes up 1 byte of information & ranges from 0 to 255 (0 being black, 255 being white)
double takes up 8 bytes of information and ranges from 0.0-1.0 (0.0 = black, 0.5 = grey, 1.0 = white)

27
Q

What command is used to save an image array into a computer?

A

imwrite(arrayName, ‘imageName.png’)

28
Q

What command is used to read in an image?

A

imread(‘fileName’)

29
Q

How to convert character array to string, etc.?

A

string(‘hello”) –> “hello”
char(“hello”) –> ‘hello

30
Q

What are the differences between strings and character arrays

A
  1. character arrays stores using single quotes - strings stored using double quotes
  2. character arrays concatenate differently
    e.g. nameList = [‘Anh’ ‘Bob’] produces a single character array ‘AnhBob’
  3. Can vertically concatenate character arrays only if the elements are the same length
  4. MATLAB strings don’t allow for indexing or element removal
31
Q

What are strings vs. character arrays good for?

A

Strings are good for storing and searching for whole words of different lengths
Character arrays are better for accessing and changing individual characters

32
Q

What is a function?

A

Code bundled together and given a name

33
Q

What is the syntax for a function?

A

function [] = functionName()
% comment describing the function
code
end

34
Q

How is a function called?

A

functionName(parameter);

35
Q

What happens when a function is called?

A
  1. the program was taken to where the function code is located
    2.the code inside the function was executed from top to bottom
  2. at the end of the function, the program is returned to where it was before the function was called
  3. the program continues
36
Q

Why do we use functions?

A
  1. to reuse code throughout a program
  2. simplify a complex task (abstraction)
37
Q

What is a function parameter?

A

Function parameter is data that is sent to the function when the function is called, and is placed inside the round brackets from the function name
e.g. function[] = greetings(“David”) has the parameter “David” that it takes from the user

38
Q

What does using a function parameter do?

A
  1. the program was taken to where the function code is located
  2. the parameters are copied to the function into the respective variables
  3. the code inside the function is executed from top to bottom
  4. the program throws away parameters and created variables from inside the function
  5. the program is returned where it was before the function was called
  6. the program continues
39
Q

What are function returns?

A

Function returns allow for a value from a function to be used throughout the program and are denoted in the square brackets
e.g. function[result] = plus2(x) will return the variable result, and has the parameter x