Question: MATLAB HELP for this example, we're going to compute and plot a correlation % matrix. A correlaton matrix is computed by correlating a 2d matrix

MATLAB HELP

for this example, we're going to compute and plot a "correlation % matrix". A correlaton matrix is computed by correlating a 2d matrix with % itself, so that any point (i,j) in the correlation matrix represents the % correlation between the data from the (ith column of the original matrix % and the jth column of the orginal matrix. Let's walk through this % step-by-step. First clear the workspace and load in the eegdata we have % been working with before (MotionEEG_01_clean.mat)

% recall that eegdat is a 3d matrix of electrodes X samples X trials. Let's % compute the ERP for all electrodes. In other words, average eegdat over % trials, so that only channels and samples are left (this should be a % 19-by-2000 matrix).

% let's compute and plot the correlation between the ERP at electrode 2 % and electrode 3. First, make a scatter plot showing the ERP at each % sample from electrode 2 on the x axis by each sample from electrode 3 % on the y axis. (you should get a plot with many dots on it, not lines). % Does the correlation look positive or negative? Weak or strong? Hint: two % nearby EEG electrodes pick up much of the same signal.

% now compute the actual correlatation (r-value) and p-value between % the ERP at electrode 2 and electrode 3 (you should get one correlaton and p-value, remember % how the corr functions works on columns!).

% Add some text to your plot from question 3.3 displaying the r and p value % from 3.4 directly on the plot with 16 fontsize. Call "lsline" (without quotes) after % you are done with your plot and it will automatically add the best-fitting % (least-squared) straight line to your data. Then label your axes and increase the fontsize to 16

% now correlate the ERP from electrode # 1 with the ERP from every other % electrode. Let's do this in a for loop that loops over each electrode and % stores the new r-value and p-value into a variable without overwriting % the previous values (rememeber, you can index into an output variable!). % if done correctly, you should get a 19-element vector of r-values (and % another of p-values) reflecting the correlation between electrode 1 and % each other electrode (including electrode 1 with itself).

% Plot the correlation value and the p-value on the same plot. % That is, make a line plot with electrode number on the x-axis and two % different y-axes: r-values on the left y-axis and p-values on the right y % axis;

figure(2)

% Now make two for loops (one nested in the other) in order to % correlate each electrode with every other electrode. Save the r values % and the p-values from each corrlation. Since each electrode is being % correlated with every other electrode, you shold end up with a 19-by-19 % matrix of r values (and one for p-values) - this is the correlation % matrix we talked about in 3.1

% read the help on the corr function - you can generate the exact same % result in 3.8 in a single line of code, without any loops, using just the corr function. Try this.

% use the imagesc function, plot the r-values from 3.8 in a 'heatmap' % style plot. The x- and y- axes should both be electrode # (one through 19) and % the color of each pixel in the heatmap should represent the correlation % value.

% make a new figure with two panels (subplots) plotting the % correlation matrix from 3.9 right next to the correlation matrix from 3.10. They should look % identical if done correctly.

% provide an answer in a text comment below. Why is the diagonal of % the correlation matrix plotted in 3.10 and 3.11 all bright yellow?

% now use the surf plot to visualize the correlation matrix as a 3d % surface.

% replot 3.13 but turn the lines on the edges of each patch of the serface plot off so % that it looks like a continious surface and make the surface semi % transparent (alpha = 0.5).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!