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

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Dyuman Joshi
Dyuman Joshi il 30 Gen 2023
"(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.

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 30 Gen 2023
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.
.

Più risposte (1)

Cris LaPierre
Cris LaPierre il 30 Gen 2023
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])

Categorie

Scopri di più su Propagation and Channel Models in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by