I calculate the correlation matrix by the way NxN.
when I check the saved file content, I did not find a N*N matrix. instead of it, I find a variable TF , stored M * 1 matrix.

My question,

how you experts stored the correlation matrix? In which way?

where the pvalue associated with Correlation matrix is stored?

How the cohr and other connectivity metris store the results.
I tried to do further analysis , so I ask such question.
In fact, your software is user friendly and almost perfect.

The connectivity matrices are compressed before they are saved. The coherence, correlation and phase-locking value are symmetric measures (AxB=BxA), so we don’t have to save twice all the values.

To get the connectivity matrix correctly formatted, you can do the following:

Read the file timefreq_connect…mat into the variable TfMat, or right-click > File > Export to Matlab > “TfMat”

R = bst_memory(‘GetConnectMatrix’, TfMat);

The matrix R is the connectivity matrix [signalsA x signalsB x Frequencies]

For PLV and coherence: he frequency bins are described in the TfMat.Freqs: R(:,:,1) is frequency TfMat.Freqs(1)

Alternatively, you can use the function export_timefreq.m: right-click on a connectivity file > File > Export to file > Save in an ASCII format (simple text file)

The p-values associated with the correlation measure are not saved. The threshold is asked as an input parameter and the output matrices are already thresholded (connectivity value set to zero).

Thank you. I got it!
Another question,
Assuming the imaging kernel (K) is sensors x the number of sources x 3, then the lead field matrix of the source 1 is K(:,1, for three orientation, or others?
What I understand is right?

Hi Great coder,
I used
R = bst_memory(‘GetConnectMatrix’, TfMat);
successfully.
However, after I change R value, how to save back the R.
using R = bst_memory(‘SaveConnectMatrix’, TfMat)?

Hi experts,
I tried to use the command
R = bst_memory(‘GetConnectMatrix’, tf_plv);

The following error appeared,

** Error: Line 1613: Undefined variable “TimefreqMat” or class “TimefreqMat.RowNames”.
**
** Call stack:
** >bst_memory.m>GetConnectMatrix at 1613
** >bst_call.m at 26
** >macro_methodcall.m at 37
** >bst_memory.m at 71
**

Would you like to solve it or tell us how to read the tfmat in other ways?
The version of brainstorm is 7 Jun, 2016.
Thank you very much.

In the processes “Correlation 1xN”, “Correlation NxN” and “Correlation AxB”, the measure that is used is the same.
In the NxN case, it just repeats it for all the pairs of signals, there is no covariance of the other signals involved.
The results are the same as the non-diagonal values returned by the corrcoef function with only two signals in input.

The full code of the function and some additional explanations are available here:

I got it, thank you.
In fact, the function calculate the correlation coefficient between each pairs of channels.

Best wishes,
Junpeng

[QUOTE=Francois;11245]Hi Junpeng,

In the processes “Correlation 1xN”, “Correlation NxN” and “Correlation AxB”, the measure that is used is the same.
In the NxN case, it just repeats it for all the pairs of signals, there is no covariance of the other signals involved.
The results are the same as the non-diagonal values returned by the corrcoef function with only two signals in input.

The full code of the function and some additional explanations are available here:

When I export correlation array file from brainstorm to matlab it is exported as structure and it is in structure.F = 2701x1
i want to convert it to 73x73 in matlab, how to do it?

I was exporting the maps, modifying them, and reimporting as per your instructions above. Everything was working fine. Then when I went to do it again this evening, something changed and it won't work.

I am now getting an error:
Call stack:
** >bst_memory.m>ReshapeConnectMatrix at 1772
** >bst_memory.m at 72
** >view_connect.m at 124
** >tree_callbacks.m at 380
** >bst_call.m at 28
** >panel_protocols.m>CreatePanel/protocolTreeClicked_Callback at 109

I noticed one peculiar thing that changed when I did: TfMat.TF=R(:);,
That was, the resulting matrix size for TF was larger than it had been when it was working.

I cannot figure out why this is happening. And I think it is difficult for you to figure out. But one workaround maybe is if you can explain how to get the R matrix back into the same shape as the original TF matrix. The extracted R is a 4-D matrix. But the TF matrix is not. In my case the TF matrix was a 1953x1x10 double. Now, after importing the R using the command TfMat.TF=R(:);, the TF matrix is 38440x1 double.

Again, this double matrix shape had worked before, but the size was smaller. I don't know why it has increased.

Depending on the connectivity measure that is used, the resulting connectivity matrix can be symmetric or not. Symmetric matrix can be compressed, with only half of the values stores (+ the diagonal).

Check the corresponding code if you need to understand what you are not doing correctly:

In the meantime, based on the other information in this thread, I was able to understand how the extracted 2-D TF matrix is arranged in the original single column, multidimensional TF matrix. I was then able to build a dummy file for a single dimension in Excel and enter values such that only the values I want to show will show, and I can display them in different colors by adjusting the color bar according to the directionality of the statistical comparison that was made. By avoiding even using the code, "get connectivity matrix" I avoid changing its shape, and can simply replace the TF matrix with the dummy one that I have made.

It's a sketchy workaround, and was a little tedious, but got the job done without me having troubleshoot code (which is not one of my strong points...yet).