How do I plot horizontal time intervals and ignore others to produce a non continous dashed line plot?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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]
CQ_HC = [0.159793814432991 0.265116279069768 0.296943231441047 0.337552742616036 0.345679012345677 0.363636363636362]
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 commentaire
Dyuman Joshi
le 30 Jan 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.
Réponse acceptée
Star Strider
le 30 Jan 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.
.
2 commentaires
Plus de réponses (1)
Cris LaPierre
le 30 Jan 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]
CQ_HC = [0.159793814432991 0.265116279069768 0.296943231441047 0.337552742616036 0.345679012345677 0.363636363636362]
x = reshape(tTime,2,[])
y = [CQ_HC;CQ_HC]
figure;
plot(x,y)
xlim([0 max(tTime)])
ylim([0 0.6])
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!