Programming Flashcards

(51 cards)

1
Q

what is length() used for

A

returns the longest dimension of a vector or array

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

what does histcounts(data, bins) do

A

bins the data into discrete intervals and returns counts per bin

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

how do you calculate mean firing rate from spike times and time range?

A

mean firing rate from spike times and time range:
length(spike_times)/(end_time - start_time)

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

what is a cell array

A

a container that stores data of varying types and sizes using {}

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

how do you index a cell array to get the content

A

{row, col} instead of ()

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

what is the function of namean()

A

calculates the mean while ignoring NaN values

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

what is zscore(data) used for

A

standardizes data by substracting the mean and dividing by standard deviation

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

how do you plot a histogram of neuron activity with 5 second bins

A

how do you plot a histogram of neuron activity with 5 second bins
bin_edges = min(times):5:max(times);
histogram(times, bin_edges);

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

what does range(x) return

A

max(x) - min(x)

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

what is the difference between a matrix and a cell array?

A

matrices store only numeric data; cell arrays can store mixed types

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

how would you check if neuron 3 fired more than 1000 times?

A

if length(active_times{3}) > 1000

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

what function is used for PCA in matlab

A

pca()

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

what does subplot(1,2,1) do

A

creates a 1-row, 2-column subplot and activates the first one

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

what does sign(x) return

A

1 if x>0 and -1 if x<0 and 0 if x==0

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

how do you loop through all neurons in a dataset stored in a cell array

A

for i = 1:length(active_times)

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

how do you define a figure with multiple subplots

A

subplot(rows, cols, index) inside a for loop

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

whats a common mistake when using && in a vector comparison

A

&& only works on scalars, use & for vectors

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

what is the purpose of smoothdata()

A

applies a smoothing algorithm to reduce noise in data

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

what does fprintf(‘Rate: %f’, rate) do

A

printe the variable rate with formatting

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

why initialize vectors with nan()

A

to reserve space and handle missing values during loops

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

function to convert radians to degrees

22
Q

how do you find spikes within a time window

A

spikes(spikes > t1 & spikes < t2)

23
Q

how do you apply a function to each cell in a cell array

A

cellfun(@function, cell_array)

24
Q

what function do you use to generate random integers without replacement

A

datasample(vector, N, ‘Replace’, false)

25
code to calculate peak firing rate uring binnin
max(histcounts(spikes, bin_edges))/bin_width
26
how to make a raster plot with time on x-axis and neuron index on y-axis
plot(spike_times, neuron_ids, '.')
27
when to use for loop vs while loop
use for when you know the number of iterations: while when you dont
28
whats the difference between plot() and scatter()
plot() is for lines; scatter() is for individual points
29
what are gcf and gca good for
get current figure gcf and current axis gca
30
how do you check for missing data
isnan()
31
what is keyboard used for
pauses execution and enters debug mode
32
explain how to bin spike times for mutual information calculation
use histcounts(spike_times, tracking_time_edges)
33
whats the role of omitnan in sum(..., 'omitnan')
ignores NaNs during summation
34
how do you update a hopfield network state in matlab
S(i) = sign(W(i,:) * S')
35
function to combine matrices vertically
vertcat(a,b) or [a;b]
36
why might a tuning curve be flat even if a neuron is active
the neuron fires uniformly across conditions, indicating no selectivity
37
how would you compute the mean firing rate for each neuron over the session
Loop over each neuron Count spikes using length(spike_times) Compute total duration using range(frame_times) Divide spikes by duration Store result in a vector
38
How would you build a tuning curve from spike times and a continuous stimulus (like head direction)
Bin head direction data (e.g. 36 bins across 0–2π) Bin spike times using same time bins Match spike bins to stimulus bins Count spikes per stimulus bin Normalize by occupancy (time spent per bin) Plot firing rate vs. stimulus
39
how would you calculate mutual information between firing and a stimulus variable
calculate tuning curve normalize firing rate to Hz calculate probability of each stimulus compute mean firing rate across all conditions Apply: sum(f_i * log2(f_i / f_mean) * p_i) Store result for each neuron
40
How would you write a function to sort neurons by their firing rate
Compute firing rate vector Use [~, idx] = sort(rates, 'descend') Return sorted neuron indices
41
How would you make a raster plot for motor cortex neurons only
Identify motor neurons (e.g. brain_area == 1) Loop over those neurons Plot each spike time at y = neuron index Use hold on to layer all neurons
42
How would you bin spikes using histcounts to calculate firing rate in time windows
Define bin edges with consistent width Use histcounts(spike_times, bin_edges) Normalize counts by bin width to get rate Store in vector and plot
43
How would you create a swarm plot to compare activity between brain areas
Compute mean firing rate per neuron Create vector of brain area labels (1, 2, 3) Use swarmchart(area_labels, mean_rates, 'k', 'filled') Label axes
44
How would you remove neurons with missing spike data
Loop through neurons Check if isnan(mean_rate(i)) Skip or remove that index from further analysis
45
How would you run PCA on neural firing data
Bin spike data for all neurons into time bins Smooth and standardize (e.g. smoothdata, zscore) Use pca(data') where rows = observations, cols = neurons Use score(:,1:2) for plotting Color by a variable (e.g. head direction)
46
How would you test whether two brain regions have significantly different firing rates
Extract mean rate vectors for each region Use ttest2(motor_rates, parietal_rates) Optionally visualize with boxplot or swarm chart
47
How would you simulate deterministic Hopfield network dynamics
Initialize pattern V Build weight matrix W using Hebbian rule Initialize state S Loop over time steps: compute h = W * S', update S using sign(h) Track overlap over time
48
How would you measure Hopfield network memory capacity
Store N random patterns Perturb a cue for one of them Run dynamics and measure which pattern is recovered Repeat for increasing number of patterns Plot recall % vs. # patterns
49
How would you generate a PSTH for multiple neurons
Define time window around each stimulus Align spike times relative to stimulus time Bin relative spike times across trials Create subplot per neuron, add vertical line at time 0
50
How would you identify the most selective neurons based on their tuning curves
Compute tuning curve for each neuron Measure width of tuning (e.g. full width at half max) Sort/select those with narrowest tuning
51
How would you calculate correlation between spike trains of two neurons
Bin spike trains into vectors (same bin edges) Use corrcoef(vector1, vector2) Optionally apply smoothing first