How to plot unequal time series with same x-axis
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi everyone,
I required to plot two unequal time series data on one plot with two y-axis. For first times series: x-axis is time dd/mm/yyyy and y-axis a veriable data length is 485 by 2. While, the second time series x-axis is time (dd/mm/yyyy) and y-axis is another varibale (data length: 60 by 2) . I tried but it didn't work:
(dataset also attached for reference)
clear all
clc
T = readtable('data.csv')
R_t=T(:,1);
R_wl=T(:,2);
R_wv=T(:,3);
E_t=T(:,4);
E_m=T(:,5);
plot(R_t,R_wl)
plot(R_t,R_wl,'-o',E_t,E_m,'-x')
댓글 수: 0
채택된 답변
Simon Chan
2022년 1월 16일
You may try the following:
T = readtable('data.csv'); % Read csv file as entire table
TT2 = table2timetable(T(:,4:5)); % Extract the 4th and 5th columns as TT2
TT1 = table2timetable(T(:,1:3)); % Convert 1st to 3rd column to TT1
TT3 = outerjoin(TT1,TT2); % Perform outerjoin
%
yyaxis left
plot(TT3.Var1,TT3.Var2,'c--'); % Plot data from Column 2 of csv file
yyaxis right
plot(TT3.Var1,TT3.Var5,'b+') % Plot data from Column 5 of the csv file
댓글 수: 0
추가 답변 (1개)
Seth Furman
2022년 9월 23일
Plotting multirate data is now easier with stackedplot, which now supports multiple timetable inputs.
T = readtable("https://in.mathworks.com/matlabcentral/answers/uploaded_files/864145/data.csv")
TT1 = table2timetable(T(:,1:3))
TT2 = table2timetable(T(:,4:5))
sp = stackedplot(TT1,TT2);
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!