Ich möchte zwei verschieden lange Arrays übereinander ploten.

16 visualizaciones (últimos 30 días)
Aaron Petersen
Aaron Petersen el 11 de Mayo de 2022
Respondida: sai charan sampara el 12 de Oct. de 2023
Guten abend,
Für ein Uniprojekt muss ich zwei Arrays in einem Plot übereinder legen. Die Arrays zeigen je einmel gemessene Kurven von Schwingung und einmal die mit Simulink berechneten Kurven. Beide Messungen haben natürlich unterschiedliche Schrittweiten und unterschiedliche Längen. Ich möchte in einem Plot beide Kurven übereinander legen mit je n Perioden. Messung1 hat 544200 Werte - Messung2 hat 200000 Werte. Zu Messung1 habe ich Time als Zeitstempel zu Messung2 leider nicht. Wie kann ich das am besten umsetzen?
Vielen Dank im Voraus!!!!!

Respuestas (1)

sai charan sampara
sai charan sampara el 12 de Oct. de 2023
Hello Aaron,
I understand that you are trying to plot two variables on same plot, but each variable has different time steps and lengths.
This can be achieved as follows. Sample both the data at timestamps that increment by the LCM of individual variables and then use the data for plotting.
Let “measurement1” has a time increment of “T1” and “measurement2” has a time increment of “T2”. Then find the LCM of “T1” and “T2” say “T3”. Then take values of “measurement1” and “measurement2” at time step of every “T3” seconds. Then use the newly obtained data to plot against time that increases with step “T3”. It can be done like the example code below.
m1=1:1:20;%m1 signal
m2=1:2:10;%m2 signal
T=50;%Time interval of the two signals [0,T]
T1=50/length(m1);
T2=50/length(m2);
T3=5;%lcm of T1 and T2
t=T/T3:T/T3:T;
m1_new=m1(1:length(m1)/length(t):length(m1));
m2_new=m2(1:length(m2)/length(t):length(m2));
plot(t,m1_new);
hold on
plot(t,m2_new);
hold off
If the timestep is not available but both the variables are measured over the same interval, then they can directly be plotted together as shown below:
T=50; %interval of measurement
t1=0:5:T;%timestamps of measurement 1
t2=0:10:T;%timestamps of measurement 2
m1=t1/5;%m1 signal
m2=t2*2/5;%m2 signal
plot(t1,m1);
hold on
plot(t2,m2)
hold off
You can refer to the below documentation to learn more about “hold on” function.
Hope this helps.
Thanks,
Charan.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!