Random & Loops Flashcards

(11 cards)

1
Q

How to generate random numbers?

A

By using the randi function:

randi(value) generates random numbers from 1 to value

randi(value, m, n) this generates random numbers from 1 to value in an mxn matrix

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

How do we use logical equality and not assignment?

A

By using == (double equality)

3 == 3 (True)

2 == 5 (False)

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

How to create conditionals?

A

Using the “if - end” statement

If condition
process if condition is true
End

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

How to display strings or variables?

A

Using the display command:

disp(“hello world”)
disp(var)

Var must contain something

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

How can we divide our code in sections?

A

By using double percentages

%% Creates a section

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

How do we run for loops?

A

for i = initial:final
Statement
end

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

For loops with jumps

A

for initial: jump : final:
Statement
end

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

How to time the process of a section of code?

A

Using tic toc built in function:

Tic

Section of code with several lines

Toc

(We can assign toc to a variable)

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

How do we create while loops?

A

while condition
Statements
end

If condition is true, statement will execute, otherwise, it will jump the the while loop

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

How to force the computer to terminate the execution of a program?

A

Ctrl + C

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

How to stop a loop after achieving what you wanted?

A

By using the “break” command.

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