how to ignore nan values in corr function?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
trailokya
il 17 Dic 2014
Risposto: Roger Stafford
il 17 Dic 2014
sir, i have a three dimensional matrix say A(129*135*33). I have to find out the correlation coefficient along the third dimension with B=[1981:2013]. i am using the following code
m1=squeeze(A(i,j,:));
m2=[1981:2013]';
p=[m1 m2];
q=p(isfinite(p(:, 2)), :); %to remove the rows with nan values
CC(i,j)=corr(q(:,1), q(:,2);
due to some grid which have only nan values the program is not working and giving the following message
Error using corr (line 87) Requires a data matrix X.
please help how to solve it?
0 Commenti
Risposta accettata
Roger Stafford
il 17 Dic 2014
Clearly there is no sensible way to compute a correlation value for two empty vectors. I would suggest that for such cases you place a NaN in the CC matrix at the corresponding i,j pair:
q = ...
if numel(q) > 0
CC(i,j) = corr(...)
else
CC(i,j) = NaN;
end
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su NaNs in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!