How to flip an ordered X-axis that is half half separated for data?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I have a plot that I want its X-axis to be reversed. My data on X-axis is showing as
[1 2 3 4 5 6 7 8 9 10 11 12] I want to reverse it in a way that it represents [6 5 4 3 2 1 12 11 10 9 8 7] (reversing it from the middle for two seperate parts). How is it possible? I tried set(gca, 'XDir','reverse') but it reverses it to [12 11 10 9 8 7 6 5 4 3 2 1]. I cannot share the code or data due to confidentiality. Thanks in advance.
0 commentaires
Réponse acceptée
Dorna
le 4 Juin 2023
1 commentaire
Star Strider
le 4 Juin 2023
Modifié(e) : Star Strider
le 4 Juin 2023
O.K.
That seems to be essentially what I wrote, although in one column not five. You can use my approach to plot it.
Plus de réponses (2)
VBBV
le 3 Juin 2023
Use xticklabels function to modify the order of axis labels
x1 = {'6','5','4','3','2','1'};
x2 ={'12','11','10','9','8','7'};
plot(rand(1,12))
xticks(1:12)
xticklabels([x1,x2])
2 commentaires
VBBV
le 3 Juin 2023
Modifié(e) : VBBV
le 3 Juin 2023
can you explain why you DONT want to actually work with plot data but still want to flip ordered x-axis values ?
v = [16 5 9 4 2 11 7 14];
v2 = v([5:8 1:4]) % Extract and swap the halves of v
% flip the values for vector v
v2 = flip(v)
% another way
v2 = v([8:-1:5 , 4:-1:1])
How can I make the V2 to be [14 7 11 2 4 9 5 16], can I use prime on 5:8'?
You can use the flip function to get the desired result as shown above
Star Strider
le 3 Juin 2023
One approach that changes the x-axis and the data —
xv = [1 2 3 4 5 6 7 8 9 10 11 12]; % Independent Variable
yv = (xv/max(xv)).^2; % Dependent Variable
xvi = [6 5 4 3 2 1 12 11 10 9 8 7]; % Indexing Vector
figure
plot(xv, yv)
grid
xticks(xv)
title('Original')
Vectors = [xv(xvi); yv(xvi)]
figure
plot(xv, yv(xvi))
grid
xticks(xv)
xticklabels(xv(xvi))
title('Reversed & Concatenated')
It may be challenging to elliminate the connecting line between 1 and 12 here. If necessary, that would require putting a NaN value at the beginning or end of the ‘xv’ and ‘yv’ vectors, and adjusting ‘xvi’ accordingly.
.
4 commentaires
Voir également
Catégories
En savoir plus sur Polar Plots 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!