Intro 3/4 Flashcards

(36 cards)

1
Q

How do you clear all variables from the MATLAB workspace?

A

Use the command: clear all

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

What does MATLAB return for logical comparisons?

A

MATLAB returns 1 for true and 0 for false.

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

What will the following MATLAB commands return?

x = 5;
x > 7
x ~= 2

A

x > 7 returns 0 (false).
x ~= 2 returns 1 (true).

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

How can you apply logical operators to an entire array?

A

Use element-wise logical comparisons.

Example:
A = [1, 5, 3, 4, 8, 3];
B = A > 2 % Returns a logical array
C = A < 5

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

What do &, |, and ~ mean in MATLAB?

A

& (AND): Both conditions must be true.
| (OR): At least one condition must be true.
~ (NOT): Inverts the logical value.

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

What does the following command do?

D = B & C;

A

It creates a logical vector where both B and C are true (i.e., where elements in A are greater than 2 and less than 5).

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

How can you use a logical array as an index in MATLAB?

A

E = A(D);

This selects elements from A where D is true.

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

What does find(D) return?

A

The indices of elements in D that are true.

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

How do you extract all values in data that belong to category 2 in cat?

A

data2 = data(cat == 2);

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

What function would you use to compute the mean while ignoring NaN values?

A

nanmean(data);

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

How do you replace specific values in an array with NaN in MATLAB?

A

data(err == 1) = NaN;

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

How do you create a logical vector for trials where reaction time (rt) was too fast (<100 ms) or too slow (>1000 ms)?

A

error = (rt < 100) | (rt > 1000);

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

How do you count the number of error trials?

A

sum(error);

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

How do you compute the mean reaction time for valid and correct trials only?

A

mean(rt(valid & ~error));

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

How do you check if reaction times were faster for targets on the left (side == 1) or right (side == 2)?

A

mean(rt(side == 1)) % Left
mean(rt(side == 2)) % Right

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

How do you correct specific values in a matrix? (Example: Fix incorrect responses for subject 2, stimuli 3, 5, and 17.)

A

data(stimno == 3,2) = 30;
data(stimno == 5,2) = 62;
data(stimno == 17,2) = 35;

17
Q

What commands should you run at the start of a MATLAB script to clear the workspace and command window?

A

clear
clc
close all

This removes all variables, clears text from the command window, and closes all figures.

18
Q

How do you generate a sequence of numbers with a specified length in MATLAB?

A

Use the linspace function.
Example:
x = linspace(0, 2*pi, 30);
This creates 30 evenly spaced numbers between 0 and 2πœ‹.

19
Q

What does the following command do?

help linspace

A

It displays the documentation for the linspace function, explaining its syntax and usage.

20
Q

What MATLAB function is used for plotting vectors as lines or points?

A

The plot function.

Example:

plot (x, y, β€˜b-o’)

Plots y against x using a blue line with circles at data points.

21
Q

How do you overlay multiple plots on the same figure?

A

Use hold on.
Example:
hold on
plot(x, z, β€˜r–’) % Adds a red dashed line

22
Q

How do you add labels, a title, and a legend to a plot?

A

xlabel(β€˜x’)

title(β€˜A couple of lines’)

legend(β€˜y = sin(x)’, β€˜z = 0.5 + cos(x/2)’)

23
Q

How do you manually set axis limits in MATLAB?

A

Use the axis function.

Example:
axis([0 10 5 15])
Sets x-axis from 0 to 10 and y-axis from 5 to 15.

24
Q

How do you load a .mat file and check its contents?

A

load lesson8
whos data
whos lists variables and their properties.

25
What command closes all figures in MATLAB?
close all Alternatively, clf clears the current figure, and cla clears just one axis.
26
How do you plot a dataset where MATLAB automatically assigns x-values?
plot(data, 'bo') % Blue circles for data points MATLAB uses indices 1 to length of data for x-axis.
27
How do you overlay a mean trendline on a dataset?
hold on plot(mean(data,2), 'r-^') Plots the mean of data using a red line with triangles.
28
How do you plot error bars for a dataset?
errorbar(mean(data,2), std(data, 0, 2), 'g-') This plots mean values with standard deviation error bars.
29
How do you create a figure with subplots in MATLAB?
figure(2) subplot(2,1,1) % First plot in a 2-row, 1-column layout plot(data, 'b*') title('Raw data') subplot(2,1,2) % Second plot bar(mean(data,2), 'r') % Bar chart for mean values hold on errorbar(mean(data,2), std(data,0,2), '.') title('Mean data')
30
What does subplot(m, n, p) do?
Creates a grid of plots with m rows and n columns, and activates subplot p.
31
How do you generate and plot a quadratic and linear function?
X = 1:10; Y = X.^2; Z = X*9; figure(3) plot(X,Y,'r-*') % Red line with stars hold on plot(X,Z,'g-s') % Green line with squares title('Two lines') legend('X squared', 'X times 9')
32
How do you load and plot real data from a .mat file?
load ex_E figure(4) plot(scoreA, iq, 'bo') hold on plot(scoreB, iq, 'rs') xlabel('Test Score') ylabel('IQ') Plots test scores (scoreA, scoreB) against iq with blue circles and red squares.
33
How do you add a least squares regression line to a plot (if the Statistics Toolbox is available)?
lsline This fits a linear trend line to scatter plot data.
34
How do you compare mean values using a bar graph with error bars?
means = [mean(scoreA) mean(scoreB)]; figure(5) bar(means) % Bar plot hold on stddevs = [std(scoreA) std(scoreB)]; errorbar(means, stddevs, '.') This plots a bar graph with standard deviation error bars.
35
How do you visualize the distribution of a dataset using histograms?
figure(6) subplot(1,2,1) hist(scoreA) % Histogram of scoreA subplot(1,2,2) hist(scoreB) % Histogram of scoreB Creates two side-by-side histograms for scoreA and scoreB.
36
How do you generate a figure with multiple subplots in one row?
subplot(1,2,1) % First plot in a 1-row, 2-column layout subplot(1,2,2) % Second plot