Matlab plotting discrete time signals

In summary, Matlab plotting is a feature that allows users to visualize data through graphs and charts. It works by using plotting functions and commands to create a visual representation of the data. To plot a discrete time signal, one needs to define the x-axis and y-axis values and use the "plot" function. The difference between plotting a continuous time signal and a discrete time signal lies in the spacing of the x-axis values. Multiple signals can be added to one plot by using the "hold on" command and customizing their appearance. Matlab plots can also be exported as image files using the "saveas" function.
  • #1
Larrytsai
228
0
hey I was just wondering if anyone can teach me how to graph a signal like this


x[n] = { 1 for 0<=n<=4
{ 0 elsewhere

im not sure how to do this, what I have tried is

x = [1 1 1 1]

but this is not a function of 'n'.
 
Physics news on Phys.org
  • #2
% You could do something like this:

n = [0:10]; % or whatever you want your limits to be
x = zeros(1,length(n));
x(1:5) = 1

stem(n, x); % fancy plotting for discrete data
 
  • #3
Thank you so much this is exactly what I was looking for!
 

1. What is Matlab plotting and how does it work?

Matlab plotting is a feature in the Matlab software that allows users to visualize data in the form of graphs and charts. It works by taking input data and using various plotting functions and commands to create a visual representation of the data.

2. How do I plot a discrete time signal in Matlab?

To plot a discrete time signal in Matlab, you will need to first define the x-axis values (time) and the y-axis values (signal amplitude). Then, you can use the "plot" function to plot the data points on a graph. You can also customize the graph by adding labels, titles, and adjusting the axis limits.

3. What is the difference between plotting a continuous time signal and a discrete time signal in Matlab?

A continuous time signal is a function of time that is defined for all values of time, while a discrete time signal is only defined at specific points in time. When plotting a continuous time signal in Matlab, the x-axis values (time) are evenly spaced, while for a discrete time signal, the x-axis values are the specific time points at which the signal is measured.

4. How can I add multiple signals to one plot in Matlab?

To add multiple signals to one plot in Matlab, you can use the "hold on" command after each "plot" function. This will allow you to plot multiple signals on the same graph. You can also customize the appearance of each signal by adjusting the line style, color, and marker.

5. Can I export a Matlab plot as an image file?

Yes, you can export a Matlab plot as an image file by using the "saveas" function. This will allow you to save the plot as a variety of image file formats, such as PNG, JPEG, or TIFF. You can also adjust the resolution and size of the image before saving it.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
754
  • Engineering and Comp Sci Homework Help
Replies
1
Views
941
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
916
  • Engineering and Comp Sci Homework Help
Replies
3
Views
912
  • Engineering and Comp Sci Homework Help
Replies
2
Views
765
  • Engineering and Comp Sci Homework Help
Replies
1
Views
818
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
Back
Top