首页 文章

绘制相关系数值与时间的关系?

提问于
浏览
0

我的相关系数值是:

corr=[0.54   0.81   0.21   0.61   0.52   0.47   -0.42   -0.20].

这些相关系数值的相应时间是:

T=[00:00 -  00:27:02    00:27:02 - 00:35:02    00:35:02 - 00:47:02     00:47 - 00:59:55   01:05:02 - 01:12    01:15 - 01:25    01:27 - 01:35  01:35 - 01:45  ].

时间以小时:分钟:秒格式给出 . 我想绘制相关系数值与时间的关系 . 另外,我希望获得95%的置信度 . 该示例在链接https://www.researchgate.net/post/plotting_correlation_coefficient_values_against_time中给出 . 任何帮助将不胜感激 . 谢谢

1 回答

  • 0

    首先,我将日期字符串拆分为开始和结束时间,然后我将它们转换为数字:

    coeffs = [0.54 0.81 0.21 0.61 0.52 0.47 -0.42 -0.20];
    T = {'00:00 - 00:27:02', '00:27:02 - 00:35:02', '00:35:02 - 00:47:02', '00:47 - 00:59:55', '01:05:02 - 01:12', '01:15 - 01:25', '01:27 - 01:35', '01:35 - 01:45'};
    % split to start and end times
    startEndTimes = cellfun(@(str) strsplit(str,' - '),T,'UniformOutput',0);
    startTimes = cellfun(@(c) c{1},startEndTimes,'UniformOutput',0);
    endTimes = cellfun(@(c) c{2},startEndTimes,'UniformOutput',0);
    % add seconds where missing
    missingSecondsIdx = cellfun(@length,startTimes) == 5;
    startTimes(missingSecondsIdx) = cellfun(@(str) [str ':00'],startTimes(missingSecondsIdx),'UniformOutput',0);
    missingSecondsIdx = cellfun(@length,endTimes) == 5;
    endTimes(missingSecondsIdx) = cellfun(@(str) [str ':00'],endTimes(missingSecondsIdx),'UniformOutput',0);
    % convert time strings to numbers
    startTimeNums = datenum(startTimes,'HH:MM:SS');
    EPS = 1e-4;
    endTimeNums = datenum(endTimes,'HH:MM:SS') - EPS;
    % interpolate coefficients on "continous" time vector
    contTime = linspace(startTimeNums(1),endTimeNums(end),200);
    repCoeffs = repmat(coeffs,[2 1]);
    repCoeffs = repCoeffs(:);
    allTimes = [startTimeNums';endTimeNums'];
    allTimes = allTimes(:);
    contCoeffs = interp1(allTimes,repCoeffs,contTime);
    % plot
    plot(contTime,contCoeffs,'b')
    hold on;
    plot(startTimeNums,coeffs,'og')
    plot(endTimeNums,coeffs,'*r')
    datetick('x','HH:MM')
    xlabel('TIME [HH:MM]')
    ylabel('CORRELATION COEFFICIENTS')
    

    enter image description here

相关问题