How to plot unequal time series with same x-axis

3 ビュー (過去 30 日間)
Andi
Andi 2022 年 1 月 16 日
回答済み: Seth Furman 2022 年 9 月 23 日
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')

採用された回答

Simon Chan
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

その他の回答 (1 件)

Seth Furman
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")
T = 485×5 table
Var1 Var2 Var3 Var4 Var5 __________ ______ _______ __________ ____ 10/11/1987 358.71 2.7064 05/08/1983 3 26/11/1987 356.51 2.2161 30/08/1983 3 12/12/1987 354.01 1.708 04/10/1983 3 04/05/1988 352.22 1.5115 17/05/1984 3 05/06/1988 356.84 2.3481 10/08/1988 3.5 24/08/1988 361 2.9182 11/11/1988 4.9 11/10/1988 360.69 3.133 29/03/1990 3 27/10/1988 360.66 3.1278 29/08/1990 3 12/11/1988 360.11 2.8967 18/12/1991 4 28/11/1988 358.16 2.2832 21/07/1992 3.2 15/01/1989 350.99 1.1689 25/10/1992 3.5 24/01/1989 349.6 0.93675 09/09/1993 3.3 09/02/1989 346.99 0.66119 28/01/1994 3.8 16/05/1989 347.54 0.7748 28/01/1996 3.2 28/09/1989 360.33 2.6684 11/08/1996 3 01/12/1989 351.61 1.1023 29/07/1997 3.7
TT1 = table2timetable(T(:,1:3))
TT1 = 485×2 timetable
Var1 Var2 Var3 __________ ______ _______ 10/11/1987 358.71 2.7064 26/11/1987 356.51 2.2161 12/12/1987 354.01 1.708 04/05/1988 352.22 1.5115 05/06/1988 356.84 2.3481 24/08/1988 361 2.9182 11/10/1988 360.69 3.133 27/10/1988 360.66 3.1278 12/11/1988 360.11 2.8967 28/11/1988 358.16 2.2832 15/01/1989 350.99 1.1689 24/01/1989 349.6 0.93675 09/02/1989 346.99 0.66119 16/05/1989 347.54 0.7748 28/09/1989 360.33 2.6684 01/12/1989 351.61 1.1023
TT2 = table2timetable(T(:,4:5))
TT2 = 485×1 timetable
Var4 Var5 __________ ____ 05/08/1983 3 30/08/1983 3 04/10/1983 3 17/05/1984 3 10/08/1988 3.5 11/11/1988 4.9 29/03/1990 3 29/08/1990 3 18/12/1991 4 21/07/1992 3.2 25/10/1992 3.5 09/09/1993 3.3 28/01/1994 3.8 28/01/1996 3.2 11/08/1996 3 29/07/1997 3.7
sp = stackedplot(TT1,TT2);

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by