Time axis as x axis
조회 수: 36 (최근 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!