how to plot a signal in the time domain?

4 ビュー (過去 30 日間)
Matthew Worker
Matthew Worker 2023 年 2 月 18 日
コメント済み: Matthew Worker 2023 年 2 月 18 日
Hello,
I want to use the vector T containing the time values and the vector av containing the mean values of measurements, in order to create a plot of the signal. However, when I use plot(T,av) (knowing that they have the same length), i get a plot like this with intersected segments:
and when i use the function sort i don't quite have the shape of a signal either:
Any other methods to do it?
Thank you for your help.

採用された回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 2 月 18 日
This issue is related to the order of the data series that can be solved using sort() fcn. See this example:
x = [7 -1 3 5 -2 8 9 0]; % Note the order of x is chaos
y = [10 15 16 12 13 17 23 24];
figure(1)
plot(x,y, 'ro-'), grid on
xlabel('x')
ylabel('y(x)')
%% DATA sorted according to x values in the ascedning order
[Xs, Idx]=sort(x, 'ascend');
Ys = y(Idx);
figure(2)
plot(Xs, Ys, 'bd-', 'linewidth', 2)
grid on
xlabel('x')
ylabel('y(x)')
  2 件のコメント
Matthew Worker
Matthew Worker 2023 年 2 月 18 日
Thank you for your answer, but I still get the curve like in the last picture in the description, is it just linked to my data?
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 2 月 18 日
Most welcome. Figure 1 is showing the unsorted (raw) data vs. Figure 2 is showing the sorted data.

サインインしてコメントする。

その他の回答 (1 件)

John D'Errico
John D'Errico 2023 年 2 月 18 日
Nope. No other methods. Plot will plot what you give it.
A common mistake made is to not understand that a vector of numbers is just a list of numbers. Without any understanding of what they represent, you have just a list of random numbers. Numbers by themselves have no intrinsic meaning.
So, first, you need to talk to the person who provided those numbers. Make sure you understand what is in there, what the numbers represent.
It may welll be that you have some data that was sampled in time repeatedly. So essentially many experiments. In that case, you want to plot each experiment sequentially, connected with lines.
plot(T,av)
will connect each point to the next eith a line. But
plot(T,av,'o')
will not connect the points sequentially.
But first, undertand what it is that you have.
  1 件のコメント
Matthew Worker
Matthew Worker 2023 年 2 月 18 日
I do have time values that are repeated, but with different average values, maybe that's what makes my curve look wrong.
Thanks for your answer.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by