Correlation coefficient calculation error

7 次查看(过去 30 天)
As I try to find correlation coefficient for the respective variables i.e. 'td' & 'cumulat', in for loop, some error is coming in the process of execution. Please help.
clear;clc;close all
S = load('DQS.mat');
F = fieldnames(S);
for n = 1:numel(F)
F1 = fieldnames(S.(F{n}));
F11{n} = F1;
% allocate the variables
nn = cell(numel(F1),1);
PArea = cell(numel(F1),1);
t_max = cell(numel(F1),1);
for n1 = 1:numel(F1)
t = S.(F{n}).(F1{n1}).cc.t;
t_max{n1} = max(t);
nn{n1} = F1{n1};
output{n1} = cumtrapz(t);
NF = @(p,q) max(output{n1}(t<=q)) - min(output{n1}(t>=p));
PArea{n1} = NF(5, 6);
end
T_max{n} = t_max;
tt = cell2mat(T_max{1,n}(:,end));
td{n} = tt./max(tt);
cumulat{n} = PArea;
[R{n},P{n}] = corrcoef(td,cumulat); %correlation coeff. calculation
end
Error using corrcoef
Cannot compute p-values for complex inputs.
  1 个评论
Jonas
Jonas 2022-6-23
can you please edit your question, format your code as code and press the compile button (green rectangle), this way we can see what is happening

请先登录,再进行评论。

采纳的回答

Mathieu NOE
Mathieu NOE 2022-6-23
hello
seems to me the code could be made simpler, why the need to make all this cell acrobatics ?
clear;clc;close all
S = load('DQS.mat');
F = fieldnames(S);
for n = 1:numel(F)
F1 = fieldnames(S.(F{n}));
F11{n} = F1;
% allocate the variables
nn = cell(numel(F1),1);
for n1 = 1:numel(F1)
t = S.(F{n}).(F1{n1}).cc.t;
t_max(n1) = max(t);
nn{n1} = F1{n1};
output{n1} = cumtrapz(t);
NF = @(p,q) max(output{n1}(t<=q)) - min(output{n1}(t>=p));
PArea(n1) = NF(5, 6);
end
td = t_max./max(t_max);
cumulat = PArea;
[R{n},P{n}] = corrcoef(td,cumulat); %correlation coeff. calculation
end
  8 个评论
Josh
Josh 2022-6-23
Thanks for your kind reconsiderations.It is resolved.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by