How do i plot many short horizontal lines when a value is available?

5 ビュー (過去 30 日間)
fadams18
fadams18 2023 年 1 月 28 日
編集済み: Dyuman Joshi 2023 年 1 月 28 日
So I have a signal X of length N. Now I have 2 vectores A and B which are time instants on the signal X. i calculate some quotient based on the differences between A and B and store in Q. I want to plot Q on the Y-axis, and x- axis will have the time axis of the signal. Now for every location on the signal where I do some Bi-Ai, I want to draw a horizontal line (horizontal marker), and its y value will correspond to the element in Q.
Can someone please help me or give me an idea?
X % some signal
A= 100x1; %selected time instants on X
B= 120x1; %selected time instants on X
N= max([length(A) length(B)])
for i=1:N
Q(i)= B(i)-A(i)
end

回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2023 年 1 月 28 日
編集済み: Dyuman Joshi 2023 年 1 月 28 日
%random data
A=randi(100,1,10)
A = 1×10
41 54 69 89 78 80 72 21 24 62
B=randi(100,1,12)
B = 1×12
63 63 76 23 28 90 52 86 22 16 41 58
%You can not use max, because A has less elements than B elements
N=min([numel(A) numel(B)]);
for i=1:N
Q=B(i)-A(i);
%two x coordinates (different values, start and end point, order doesn't matter)
%two y coordinates (same value)
plot([A(i) B(i)],[Q Q])
hold on
end
axis fill

カテゴリ

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