How to plot time format
조회 수: 9 (최근 30일)
이전 댓글 표시
I have two time matrices of t1=3x250 and t3=3x450 with 3 columns representing hour, minute and second as integers. I also have two vectors X1 and X2 of size 1x450 and 1x250 respectively. I know on the SAME graph want to plot X1 and x2 against t1 and t2 where each observation on x axis would read in format hour:minute:second. Probably very easy to do. Could anybody guide me please?
댓글 수: 0
답변 (2개)
Star Strider
2017년 1월 14일
It would be easier with your data.
Here is one possibility with created data:
t1 = [0 1 2; 0 2 3; 1 1 10; 1 39 45]; % Original ‘t1’ ‘Hour Minute Second’ Matrix
t1a = [repmat([2017 0 0], size(t1,1), 1) t1]; % Concatenate With ‘[year month day]’
dnv1 = datenum(t1a); % Convert To Date Numbers
x1 = rand(size(dnv1)); % Data ‘x1’
t2 = [0 2 10; 0 3 5; 1 2 20; 2 30 15]; % Original ‘t2’ ‘Hour Minute Second’ Matrix
t2a = [repmat([2017 0 0], size(t1,1), 1) t2];
dnv2 = datenum(t2a);
x2 = rand(size(dnv2));
figure(1)
plot(dnv1, x1)
hold on
plot(dnv2, x2)
hold off
datetick('x', 'hh:mm:ss', 'keepticks')
댓글 수: 1
Steven Lord
2021년 5월 4일
Now you'd probably want to use a duration array.
h = randi(3, 1, 10);
m = randi([0 59], 1, 10);
s = randi([0 59], 1, 10);
D = sort(duration(h, m, s));
data = minutes(D-D(1)).^2; % minutes from start squared
plot(D, data, 'o-')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!