index in a reshaped matrix

I'm quite new to matlab. So far, I've managed my way with help and forum, but now I got stuck.
I'm trying to correlate a matrix R [114 x 1] with a matrix P [114 x 22 x 13 x 71]. I've tried both 1) cor = zeros(22 x 13 x 71); p = zeros(22 x 13 x 71); [cor,pval] = corr(R, P)
or simply 2) [cor,pval] = corr(R,P) % without first creating an empty matrix
In both cases, I get size(cor) = 20306 which I then reshape into my original P (22x13x71).
My first question is whether I can assume, as I've done now, that the correlation + reshaping will keep the exact order I had in my original matrix P. The second question, which is the one I'm struggling with, is how to get the right indexes. I'm trying to find where pval < .05 x = find(pval < .05) but that gives me indexes which I don't know how to refer back to (22x13x71). So in other words, it does not suffice to know the indexes. I need to know where the indexes fall in P.
I think this is a very simple question but I've already tried everything I know. Thanx a lot

 Accepted Answer

psz = size(P);
[p1,p2] = corr(R,reshape(P,psz(1),[]));
idx = p2 < .05;
out = P(:,idx);

1 Comment

Thank you, Andrei, that was almost what I needed. But I wasn't clear enough in my question, I'm afraid.
The thing is that p2 (22 x 13 x 71) refers to 22 channels, 13 frequency points, and 71 time points. What I need to know is which of the channels x frequency x time are < .05.
What confuses me is that even if I reshape idx to (22 x 13 x 71), I still don't know what, for example, idx(22) is. Is it the 22nd cell in idx (1,1,22)? I mean, first element of first dimension, first element of 2nd dimension, 22nd element of third dimension?
Sorry if the question seems really stupid, but I think that's the crucial lack of knowledge from my side.
thanx again a lot!

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!