How do I plot horizontal time intervals and ignore others to produce a non continous dashed line plot?

조회 수: 2 (최근 30일)
I have this code that produces this code below
tTime =[0.0547083333333333 0.0553541666666667 0.0587500000000000 0.0599375000000000 0.0632291666666667 0.0646458333333333 0.0680000000000000 0.0696666666666667 0.0729375000000000 0.0746875000000000 0.0780000000000000 0.0798333333333333]
tTime = 1×12
0.0547 0.0554 0.0587 0.0599 0.0632 0.0646 0.0680 0.0697 0.0729 0.0747 0.0780 0.0798
CQ_HC = [0.159793814432991 0.265116279069768 0.296943231441047 0.337552742616036 0.345679012345677 0.363636363636362]
CQ_HC = 1×6
0.1598 0.2651 0.2969 0.3376 0.3457 0.3636
figure;
x = tTime(1:2:end); % every 2 elements of B
y = CQ_HC; % A is y-axis
plot(x,y')
xlim([0 max(tTime)])
ylim([0 0.6])
However I dont want a continues line. Every 2 element in tTime corresponds to an element in CQ_HC.
what I want:
every two element in tTime will be a line (so first point the begining of the line and second point the end of the line). and since the x axis is a time axis, between every pair if there is no corresponding value in CQ_HC it
stay blank. in that way the plot will not be a continues line. Any ideas?
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2023년 1월 30일
"(so first point the begining of the line and second point the end of the line)"
It's not clear what this means.
Do you want to plot lines with x values taken in pair -
1 > consequetively like x(1)-x(2), x(3)-x(4), x(5)-x(6) ...
2 > or from both ends like x(1)-x(12), x(2)-x(11), x(3)-x(10) ...
If not any of 1 or 2, then mention specifically.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2023년 1월 30일
Try this —
tTime =[0.0547083333333333 0.0553541666666667 0.0587500000000000 0.0599375000000000 0.0632291666666667 0.0646458333333333 0.0680000000000000 0.0696666666666667 0.0729375000000000 0.0746875000000000 0.0780000000000000 0.0798333333333333];
CQ_HC = [0.159793814432991 0.265116279069768 0.296943231441047 0.337552742616036 0.345679012345677 0.363636363636362];
x = reshape(tTime,2,[]); % Reshape To (2x6) Matrix
y = [1;1]*CQ_HC; % Create As (2x6) Matrix
figure;
plot(x, y, 'LineWidth',2)
xlim([0 max(tTime)])
ylim([0 0.6])
To plot them all ion the same color, specify the color. I used 'LineWidth',2 so the lines would be visible. Change that as necessary.
.

추가 답변 (1개)

Cris LaPierre
Cris LaPierre 2023년 1월 30일
You need to make each 'line' its own series. Do this by reshaping your data so each time interval is in its own column.
tTime =[0.0547083333333333 0.0553541666666667 0.0587500000000000 0.0599375000000000 0.0632291666666667 0.0646458333333333 0.0680000000000000 0.0696666666666667 0.0729375000000000 0.0746875000000000 0.0780000000000000 0.0798333333333333]
tTime = 1×12
0.0547 0.0554 0.0587 0.0599 0.0632 0.0646 0.0680 0.0697 0.0729 0.0747 0.0780 0.0798
CQ_HC = [0.159793814432991 0.265116279069768 0.296943231441047 0.337552742616036 0.345679012345677 0.363636363636362]
CQ_HC = 1×6
0.1598 0.2651 0.2969 0.3376 0.3457 0.3636
x = reshape(tTime,2,[])
x = 2×6
0.0547 0.0587 0.0632 0.0680 0.0729 0.0780 0.0554 0.0599 0.0646 0.0697 0.0747 0.0798
y = [CQ_HC;CQ_HC]
y = 2×6
0.1598 0.2651 0.2969 0.3376 0.3457 0.3636 0.1598 0.2651 0.2969 0.3376 0.3457 0.3636
figure;
plot(x,y)
xlim([0 max(tTime)])
ylim([0 0.6])

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by