samples=[36.34 103.48 170.72 242.14 303.85 414.85 640.49 1396.45 1726.12 ; 6.579 5.949 8.979 7.293 7.497 2.732 1.659 1.244 1.115 ]'; % 自助抽样1000次 nboot = 1000; samples_idx = bootstrp(nboot, @(y) randsample(length(y), length(y), true), samples); samples_x = samples(:, 1); samples_y = samples(:, 2); % 检测1000次抽样的均值变点及其对应X change_points = []; % 初始化为空矩阵 for i = 1:nboot mean_left = mean(samples_y(samples_idx(i, 1:5))); mean_right = mean(samples_y(samples_idx(i, 6:9))); idx = find(mean_right < mean_left, 1, 'first'); if isempty(idx) idx = length(samples_x); % 没有变点时,赋值为最大值 end change_points = [change_points; [idx, samples_x(idx)]]; end % 计算频次直方图和累积频率 [counts, edges] = histcounts(change_points(:,2), 'Normalization', 'count'); cdf = cumsum(counts); cdf = cdf / max(cdf); % 绘制双Y轴图 figure; yyaxis left; bar(edges(1:end-1), counts,0.3, 'histc'); xlim([-100 1800]); ylim([0 650]); ylabel('Count'); yyaxis right; plot(edges(1:end-1), cdf, 'LineWidth', 2); ylim([0 1.2]) ylabel('Cumulative Frequence'); xlabel('Distance'); legend('Frequence Count','Cumulative Frequence'); 未定义与 'double' 类型的输入参数相对应的函数 'histcounts'。
时间: 2023-06-16 08:08:35 浏览: 253
这个错误提示是因为你的 MATLAB 版本比较旧,没有包含 histcounts 函数。你可以使用 hist 函数代替,代码如下:
samples=[36.34 103.48 170.72 242.14 303.85 414.85 640.49 1396.45 1726.12 ; 6.579 5.949 8.979 7.293 7.497 2.732 1.659 1.244 1.115 ]'; % 自助抽样1000次 nboot = 1000; samples_idx = bootstrp(nboot, @(y) randsample(length(y), length(y), true), samples); samples_x = samples(:, 1); samples_y = samples(:, 2); % 检测1000次抽样的均值变点及其对应X change_points = []; % 初始化为空矩阵 for i = 1:nboot mean_left = mean(samples_y(samples_idx(i, 1:5))); mean_right = mean(samples_y(samples_idx(i, 6:9))); idx = find(mean_right < mean_left, 1, 'first'); if isempty(idx) idx = length(samples_x); % 没有变点时,赋值为最大值 end change_points = [change_points; [idx, samples_x(idx)]]; end % 计算频次直方图和累积频率 [counts, edges] = hist(change_points(:,2),10); cdf = cumsum(counts); cdf = cdf / max(cdf); % 绘制双Y轴图 figure; yyaxis left; bar(edges(1:end-1), counts,0.3, 'histc'); xlim([-100 1800]); ylim([0 650]); ylabel('Count'); yyaxis right; plot(edges(1:end-1), cdf, 'LineWidth', 2); ylim([0 1.2]) ylabel('Cumulative Frequence'); xlabel('Distance'); legend('Frequence Count','Cumulative Frequence');
阅读全文