-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_basic.m
More file actions
59 lines (48 loc) · 2.21 KB
/
Copy pathexample_basic.m
File metadata and controls
59 lines (48 loc) · 2.21 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
%% FastSense Basic Example — 10M Points Single Line
% Demonstrates basic usage with a large time series dataset, plus setScale
% for logarithmic axes.
projectRoot = fileparts(fileparts(fileparts(mfilename('fullpath'))));
run(fullfile(projectRoot, 'install.m'));
n = 10e6;
x = linspace(0, 100, n);
y = sin(x * 2 * pi / 10) + 0.5 * randn(1, n);
fprintf('Creating FastSense with %d points...\n', n);
tic;
fp = FastSense();
fp.addLine(x, y, 'DisplayName', 'Noisy Sine', 'Color', [0 0.4470 0.7410]);
% Alarm thresholds (red, dashed)
fp.addThreshold(2.0, 'Direction', 'upper', 'ShowViolations', true, ...
'Color', 'r', 'LineStyle', '--', 'Label', 'Alarm Hi');
fp.addThreshold(-2.0, 'Direction', 'lower', 'ShowViolations', true, ...
'Color', 'r', 'LineStyle', '--', 'Label', 'Alarm Lo');
% Warning thresholds (orange, dotted)
fp.addThreshold(1.5, 'Direction', 'upper', 'ShowViolations', true, ...
'Color', [1 0.6 0], 'LineStyle', ':', 'Label', 'Warn Hi');
fp.addThreshold(-1.5, 'Direction', 'lower', 'ShowViolations', true, ...
'Color', [1 0.6 0], 'LineStyle', ':', 'Label', 'Warn Lo');
fp.render();
fprintf('Rendered in %.3f seconds. Try zooming and panning!\n', toc);
title(fp.hAxes, 'FastSense — 10M Points');
legend(fp.hAxes, 'show');
%% setScale — logarithmic Y axis
% Exponential growth data is best viewed with log scaling
n2 = 1e6;
x2 = linspace(1, 1000, n2);
base2 = exp(x2 / 200);
y2 = base2 .* (1 + 0.1 * abs(randn(1, n2)));
fp2 = FastSense();
fp2.addLine(x2, y2, 'DisplayName', 'Exponential Growth');
fp2.addThreshold(100, 'Direction', 'upper', 'ShowViolations', true, ...
'Label', 'Warning');
% Switch Y axis to log scale (can be called before or after render).
% Setting it before render() lets the axis autoscale directly in log space.
% Try fp2.setScale('YScale', 'linear') to toggle back.
fp2.setScale('YScale', 'log');
fp2.render();
title(fp2.hAxes, 'setScale — Logarithmic Y Axis');
fprintf('setScale() demo: Y axis switched to log scale.\n');
%% updateData — replace line data on an already-rendered plot
newY = cos(x * 2*pi/15) + 0.4*randn(1, n);
fp.updateData(1, x, newY);
title(fp.hAxes, 'updateData — line data replaced in-place');
fprintf('updateData() replaced 10M-point line data on the first plot.\n');