Time axis as x axis
38 次查看(过去 30 天)
显示 更早的评论
Hi guys, I have signal which it's a vector like
signal=[0.4 0.6 0.8 -0.8 -0.9 0.7];
t=1:length(signal); % in sec
I want to plot the time as x axis, so what Im doing is plot(signal) ; is that correct what I get is in my plot y as related to time? I mean the x axis that I get from plot(signal) is the time in seconds? if not , how can I plot my signal(y axis) in relation with time in sec(time is x axis ) ?
In addition, once we do just plot(signal), if the x axis isn't time so what does x axis represent in that case?
thanks alot for any assistance!
0 个评论
回答(3 个)
Paresh yeole
2020-7-15
编辑:Paresh yeole
2020-7-15
When you do
plot(signal)
Matlab plots the signal values for each data point. But if your x-axis do not vary in the steps of 1, then its better to use
plot(t,signal)
where t can have any step size as long as the lenght of both vectors is same.
0 个评论
Adam Danz
2020-7-15
编辑:Adam Danz
2020-7-16
Assuming you've got a vector of time stamps the same size as the signal vector, convert the time stamps to datetime values and then plot,
plot(dateTimeValues, signal)
The x axis will be in datetime (or duration if your x data are duration units).
If you don't have a vector of time stamps or durations, it would be easy enough to create.
0 个评论
Steven Lord
2020-7-16
编辑:Steven Lord
2020-7-16
- If Y is a vector, then the x-axis scale ranges from 1 to length(Y).
- If Y is a matrix, then the plot function plots the columns of Y versus their row number. The x-axis scale ranges from 1 to the number of rows in Y.
- If Y is complex, then the plot function plots the imaginary part of Y versus the real part of Y, such that plot(Y) is equivalent to plot(real(Y),imag(Y))."
As stated, your signal variable is a real vector so "the x-axis scale ranges from 1 to length(Y)." The two plots created by the code below should be the same.
signal=[0.4 0.6 0.8 -0.8 -0.9 0.7];
figure
plot(signal)
figure
plot(1:length(signal), signal)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!