0
\$\begingroup\$

I am simulating a complete system for control loop. since I need the data to be saved on matlab, I wrote a small code that saves the data in matlab and I could plot. my system has a sample time of 156Hz, so on the scope I can see this sampling as you see on the pic enter image description here Now after writing the code in matlab to save the same plot is:

x_sim= (dummy.time);
x_sim1 = x_sim(1:end);
y_sim = (dummy.signals);
y_sim1 =y_sim.values(1:end);
plot(x_sim1,y_sim1)
xlabel('time in seconds');
ylabel('voltage');

here is the plot of the output: enter image description here I used structure with time to save the data of the signal. here is the simulink scope and workplace enter image description here

\$\endgroup\$
2
\$\begingroup\$

You are plotting discrete time points using the plot function which will simply join the dots. The data points don't give any indication of what is going on between the points.

The other graph which I presume is from Simulink will be using a sample-hold plotting such that it will plot the same value over time until it changes. This is equivalent to the stairs function in MATLAB.

Which one is "correct", who knows, only you know what the system you are measuring. The two plots are just two different ways of displaying the data.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ in the first graph is from simulink scope which I wanted to use plot to show it on matlab plot as you said. so if I want to plot in matlab exactly what I see in the simulink scope, how I am supposed to do? my system has a sampling frequency of 156Hz and when I measure it on the scope it is correct but not in matlab plot \$\endgroup\$ – Yaakov May 12 at 10:16
  • \$\begingroup\$ @Yaakov "This is equivalent to the stairs function in MATLAB" \$\endgroup\$ – Tom Carpenter May 12 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.