-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotSoftClockRate.m
More file actions
68 lines (57 loc) · 2.34 KB
/
PlotSoftClockRate.m
File metadata and controls
68 lines (57 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
%% 逻辑时钟速率 (Soft Clock Rate) 专项分析脚本
clc; clear; close all;
%% 1. 加载仿真数据
% 弹出对话框让用户选择要分析的 trainData 文件
[fileName, filePath] = uigetfile('SimData\*.mat', '请选择要分析的 trainData 文件');
if isequal(fileName, 0)
disp('用户取消了选择');
return;
end
% 加载数据
load(fullfile(filePath, fileName), 'trainData');
fprintf('成功加载数据文件: %s\n', fileName);
%% 2. 数据维度提取与转置
% Train.m 中保存的维度是 [NodeNUM, Sync_CNT_NUM + 1]
% 为了方便 plot 画图,我们将其转置为 [Sync_CNT_NUM + 1, NodeNUM]
rateData = trainData.Soft_Clock_Rate_Record';
[syncIters, numNodes] = size(rateData);
iterations = 0 : (syncIters - 1); % X轴:迭代次数
% 提取领导者和跟随者的索引
isLeader = trainData.IsLeader;
followerIdx = find(~isLeader);
leaderIdx = find(isLeader);
%% 3. 画图配置
figure('Name', '逻辑时钟速率分析 (Soft Clock Rate)', 'Position', [150, 150, 1000, 700]);
hold on; grid on; box on;
% 预定义高对比度颜色矩阵
followerColors = [
0.0000, 0.4470, 0.7410; % 蓝色
0.4660, 0.6740, 0.1880; % 绿色
0.4940, 0.1840, 0.5560; % 紫色
0.8500, 0.3250, 0.0980; % 橙色
0.3010, 0.7450, 0.9330; % 青色
0.9290, 0.6940, 0.1250; % 黄色
0.2500, 0.2500, 0.2500 % 深灰色
];
legendHandles = [];
legendLabels = {};
colorIdx = 1;
% ---------------------------------------------------------
% 1. 绘制主图 (全景)
% ---------------------------------------------------------
for i = 1:numNodes
if isLeader(i)
h = plot(iterations, rateData(:, i), 'r-', 'LineWidth', 2);
legendHandles(end+1) = h; %#ok<AGROW>
legendLabels{end+1} = sprintf('Node %d (Leader)', i); %#ok<AGROW>
else
h = plot(iterations, rateData(:, i), '--', 'Color', followerColors(colorIdx, :), 'LineWidth', 1.5);
legendHandles(end+1) = h; %#ok<AGROW>
legendLabels{end+1} = sprintf('Node %d (Follower)', i); %#ok<AGROW>
colorIdx = mod(colorIdx, size(followerColors, 1)) + 1;
end
end
legend(legendHandles, legendLabels, 'Location', 'northeast', 'NumColumns', 2, 'FontSize', 9);
title('全网节点逻辑时钟速率演进轨迹', 'FontSize', 12, 'FontWeight', 'bold');
xlabel('同步迭代次数 (Sync Count)');
ylabel('时钟速率 (无量纲)');