figure a simulink data, time on x axis and data on y axis using stairs function in matlab

You can use MATLAB's stairs function inside Simulink to plot data on the Y-axis and time on the X-axis as shown in the following steps:

  1. Create a new Simulink model and open it.
  2. Drag a "To Workspace" block from the Simulink library to the model.
  3. In the "To Workspace" block parameters, set the "Save format" to "Array" and provide a name for the array, for example "myData".
  4. Drag a "Step" block from the library to the model and connect it to the "To Workspace" block.
  5. Double-click the "Step" block and configure the step to have a "Time" of "0:0.1:10" and an "Amplitude" of "0:0.5:5".
  6. Add a "Scope" block from the library to the model and connect it to the output of the "Step" block.
  7. Double-click the "Scope" block to open the scope.
  8. Set the "Time span" to "10" and the "Y-Limits" to "-1" and "6".
  9. In the Simulink toolbar, click "Simulation > Model Configuration Parameters".
  10. In the "Model Configuration Parameters" window, go to the "Data Import/Export" tab.
  11. Under "Data Export", check the box next to "Output" and select "myData" as the output variable name.
  12. Click "OK" to close the configuration window.
  13. Run the simulation by clicking "Simulation > Start" or pressing "Ctrl+T".
  14. After the simulation finishes, in the MATLAB command window, type stairs(myData) to plot the data using the stairs function.

The resulting figure should show a graph with time on the X-axis and the data on the Y-axis, plotted using the stairs function.

gistlibby LogSnag