Matlab Flashcards

(44 cards)

1
Q

Is matlab compiled or interpreted?

A

Interpreted, this means it can be run interactively with scripts and by calling functions

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

clc

A

clear the command window

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

clear

A

clear the workspace (erase all variables from memory)

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

clear var_name

A

erase variable var_name from memory

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

help fcn_name

A

get basic information about fcn_name

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

What would A(: , 2) return?

A

The 2nd column of A

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

What would A(4 , :) return?

A

The 4th row of A

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

What would A(:, 2:3) return?

A

The 2nd and 3rd columns of A

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

Where does indexing start in Matlab?

A

At 1

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

How do we define character arrays?

A

With single quotes, for example ‘ENAS130’

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

What happens if you try to multiply a character array by a scalar?

A

The ASCII values of the elements of the character array would be multiplied by the scalar

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

What does size() return?

A

Returns the number of rows and columns

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

What does length() return?

A

Returns the length of the largest array dimension

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

What does height()/width() return?

A

Height returns number of rows, width returns number of columns

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

How do you save data into a .mat file?

A

save(filename) will save all variables and values currently in the workspace to a .mat file

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

How do you load data from a .mat file?

A

load(‘filename’, ‘variables’) if wanting to load specific varaibles, else load filename.mat

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

How do you view file contents without loading them in?

A

whos -file filename

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

How do you save info to a .dat file?

A

save filename.dat -ascii var1 var2, or without var1 and var2 if you want to save all variables

19
Q

How do you load data from a .dat file?

A

load filename.dat -ascii

20
Q

How do you use colon notation?

A

initVal : step : endVal

21
Q

How do you use the linspace function?

A

linspace(initVal, endVal, length of vector)

22
Q

How can you easily initialize a vector of equal values?

A

x = scalar * ones(1,3)

23
Q

What does max return?

A

returns the maximum value and its index

24
Q

What does polyfit do?

A

finds the best-fit line coefficients

25
What does polyval do?
evaluates the best-fit line
26
What does sum do?
Sums all the elements across a row vector, or down a column
27
How do you use find()?
To get the indices of elements equal to a certain integer, find(myArray==3)
28
How do you use unique()?
To list unique elements in increasing order, unique(myArray)
29
How do you use any()?
To test if at least one element equals a certain int, returns 1 if true, 0 if false. any(myArray==3)
30
How do you use all()?
To test if all elements equal a certain int, all(myArray==3)
31
What does input do?
get user input from the command window
32
What does disp do?
displays unformatted output
33
What does num2str do?
converts numbers to strings
34
What does sprintf do?
create formatted strings (without displaying)
35
What does fprintf do?
prints formatted info to the command window
36
What does fscanf do?
reads formatted info from a file
37
What is the syntax for fopen?
fopen(filename, access_type). the access type if 'wt' if writing to a file, 'rt' if reading from a file
38
When using fprintf, what would be returned if printing 8 doubles with a \n?
72, 8 bytes for every double and 8 for each \n
39
In what cases is a semicolon needed?
when assigning a value or returning information from a function
40
What is the matlab equivalent of !=?
~=
41
What is the matlab equivalent of &&?
&
42
If a function is defined in the same file that it is used, where must it be defined?
After the script that calls it?
43
If a function is defined in another file, what are the constraints?
only one function per file, file must be in the same folder or path, and the filename must be fcn_name.m
44
How do you use fprintf?
fprintf(fileID, format, data) example: fprintf(outputFile, '%f\n', matrix1)