Correlation coefficent for vectors (of unequal lengths).

21 views (last 30 days)
I have two separate vectors (A and B) which I want to caculate '[r,p] = corrcoef(A,B)' for. They are the same length but both contain 'NaN' so I can't use corrcoef. Both vectors follow a time series so I can't remove the nans separately in each vector as the rows of data will then be out of sequence.
Is there a way of removing an entire row in both A and B if one of them contains a nan on a particular row so that they remain in synch with each other?
If not is there another method I can use?

Accepted Answer

Daniel Shub
Daniel Shub on 25 Jul 2013
Edited: Daniel Shub on 25 Jul 2013
First make some dummy data
A = 1:10;
A(2) = nan;
B = 1:10;
Then combine the arrays into a matrix so it is easy to work with
C = [A; B];
Then only keep columns for which not any of the rows are nan
D = C(:, ~any(isnan(C)))
Finally split the matrix into two new arrays
Aprime = D(1, :);
Bprime = D(2, :);

More Answers (1)

Narges M
Narges M on 25 Jul 2013
use isnan() function to skip those rows

Sign in to comment.


Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!