How to plot two arrays which different time stamps and lengths in one plot?

4 Ansichten (letzte 30 Tage)
Hello everyone,
I have Data extracted from a csv which looks like:
A=[0.1 0.2 0.35 0.42] which represents the time and with the corresponding B=[1 4 9 12 20] data
and I have another Data set with
C=[0.01 0.4 0.5 0.8 1 2 10] which also is the time and the corresponding data D=[5 7 10 11 12 3 1]
How can I plot both vectors B and D over one time line?
I tried to extend the vector A and fill it up with zeros for the missing time stamps, but in the plot the last point and the first one were connected by a line for data A .
Any ideas?
Thank you very much for your help
Helmut

Antworten (1)

Fangjun Jiang
Fangjun Jiang am 18 Feb. 2021
%%
A=[0.1 0.2 0.35 0.42];
B=[1 4 9 12];
C=[0.01 0.4 0.5 0.8 1 2 10];
D=[5 7 10 11 12 3 1];
[x,index]=sort([A,C]);
y=[B,D];
y=y(index);
plot(x,y)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by