Pearsons correlation using corrcoef not working

4 Ansichten (letzte 30 Tage)
Elizabeth Lees
Elizabeth Lees am 24 Mär. 2021
Kommentiert: William Rose am 24 Mär. 2021
I am trying to calculate the pearsons correlation between two variables in a timetable. I am utalising the corrcoef() function. However the output it gives me is always NaN NaN NaN NaN. Why is this? How can I fix this?
  4 Kommentare
Elizabeth Lees
Elizabeth Lees am 24 Mär. 2021
@William Rose Thank you for your answer. I have discovered it was because many rows of the numerical data contained NaN values, I have now used 'Rows', 'Pairwise' to discard these in the statistics and am now recieving results. However when just the NSE() function to calculate the Nash-Sutcliffe value between the variables I am still getting an NaN result I believe for the same problem however 'Rows', 'Pairwise' doesn't seem to work within the NSE() function, do you know of another way to discard these empty rows to calculate the Nash-Sutcliffe?
Example code:
NSE(combined_data.Observed_Rio_Branco,combined_data.Simulated_Rio_Branco, 'Rows', 'pairwise')
Error using NSE
Too many input arguments.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

William Rose
William Rose am 24 Mär. 2021
This code eliminates each row with one or more NaNs. Thank you to @Jan for this.
X = rand(10, 4);
X(X < 0.1) = NaN;
disp(X); %array containing NaNs
X(any(isnan(X), 2), :) = []; %delete rows with NaN
disp(X) %array with NaN rows removed
  1 Kommentar
William Rose
William Rose am 24 Mär. 2021
Assumng your input data are column vectors, you would do
%make a Nx2 array
A(any(isnan(A), 2), :) = []; %delete rows with NaN
I do not have the NSE() function so I cannot test the code above.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)


Mehr zu Descriptive Statistics finden Sie in Help Center und File Exchange





Community Treasure Hunt

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

Start Hunting!

Translated by