How to change the time from seconds to hours of a plot from Simulink
11 views (last 30 days)
Show older comments
Hi, my knowledge of Matlab is very limited. I have a two signals from Simulink that I want to plot on a Matlab script. I sent my signals to the workspace and they come out as a 1x1 double timeseries. I want to change the timebase of my graphs from seconds to hours, since I'm simulating for 650000 seconds. I just don't know how to modify the time from my plots. Could someone help please?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1355633/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1355638/image.png)
0 Comments
Answers (1)
Gokul Nath S J
on 17 Apr 2023
Hi Pierre-François Neumann-Chayer,
Based on my understanding of your request, it seems that you have simulated a system and have sent the output signal to the MATLAB workspace. In order to plot the signal, you would like to convert the x-axis from seconds to hours.
To achieve this, you can use the "To Workspace" block in Simulink. Once the simulation is complete, the data stored in Timeseries format will be available in a variable named 'out' in the workspace. Using the dot notation, you can access the data and time instant of the signal.
x_data = out.simout.Data;
t_data = out.simout.Time;
Once you have accessed the time data using the dot notation as mentioned earlier, you can apply this conversion to the time values by dividing them by 3600. This will give you the time values in hours, which you can then use to plot the signal data accordingly.
plot(t_data/3600, x_data);
with regards,
Gokul Nath S J
0 Comments
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!