“plot” function for some repetitive X values

Hi, I would like to use “plot” function for some repetitive X values e.g: 1:10 and again 10:1 but the Y values are differ(in one curve).
I want to show effect of increasing value [1:10] and the decreasing value [10:1] in one figure.*
Could you please let me know what the solution is?
Thanks,

1 commentaire

Deepak Sharma
Deepak Sharma le 25 Mai 2021
Modifié(e) : Deepak Sharma le 25 Mai 2021
I need help in below plot, my xaxis values = [0 10 20 30 40 50 60 70 80 90 80 70 60 50 40 30 20 10 0]. i want to unfold this graph so that my xaxis must follow the original trend ie 0-->90-->0.

Connectez-vous pour commenter.

 Réponse acceptée

Lucas García
Lucas García le 29 Août 2011
I am not sure if I understand correctly.. is this what you are looking for?
myTicks = 1:20;
y = rand(1,length(myTicks));
plot(myTicks,y)
set(gca, 'xTick', myTicks);
% Modifying Tick Labels in X-axis
myTicks(myTicks > 10) = 10:-1:1;
set(gca, 'xTicklabel', myTicks)
----------
Update after comment.
Let X be a matrix with two columns and the values in your comment:
plot(X(:,2))
set(gca, 'xTick', 1:size(X,1))
set(gca, 'xTicklabel','')
h = get(gca, 'XLabel');
set(h,'Units','data');
pos = get(h,'Position');
y = pos(2);
hLabels = zeros(1,size(X,1));
labels = num2str(X(:,1));
for i = 1:size(labels,1)
hLabels(i) = text(i,y,labels(i,:));
end
set(hLabels,'Rotation',45,'HorizontalAlignment','right')
Or you can do:
plot(X(:,2))
set(gca, 'xTick', 1:size(X,1))
set(gca, 'xTicklabel', num2str(X(:,1)))
and use XTICKLABEL_ROTATE to rotate the X-labels.

5 commentaires

KU
KU le 29 Août 2011
Thanks very good approach, but if the X values (and Y value)are as follows what is your suggestion:
Xvalue: YValue:
37.3940291 14860.75949
27.55755388 19113.92405
23.10120535 15586.49789
20.22882759 18481.01266
18.01295354 15983.12236
16.38726285 16286.91983
14.95379794 16658.22785
13.70989555 16759.49367
12.58615174 16700.42194
11.59731113 15544.3038
10.75376355 15628.69198
9.947094575 15932.48945
9.235245842 15434.59916
8.566337569 15696.20253
7.939650648 15130.80169
7.36433843 15215.18987
6.822362566 15400.84388
6.304337611 15004.21941
5.811550906 15147.67932
5.360799319 14413.50211
4.941224431 15097.04641
4.525412755 14852.32068
4.12032583 15316.4557
3.744600743 14345.99156
3.400057958 14616.03376
3.120381752 13670.88608
3.25267612 13189.87342
4.879741922 11198.31224
7.212135739 22759.49367
10.61391919 22295.35865
16.22155704 28987.34177
35.12703384 30776.37131
32.74118231 30835.44304
25.76381219 30776.37131
22.01304747 30835.44304
19.41287365 30776.37131
17.39966654 30776.37131
15.7698445 30835.44304
14.45311027 29392.40506
13.24725743 22025.31646
12.1906177 22067.51055
11.28467634 22371.30802
10.44572906 22329.11392
9.683630887 22236.28692
8.97903786 22227.8481
8.329970265 22236.28692
7.723710397 23147.67932
7.158589071 23375.52743
6.630869304 23282.70042
6.157635698 20464.13502
5.657967089 10987.34177
5.210281538 10995.78059
4.78405358 11012.65823
4.376897035 10987.34177
3.981984125 12185.65401
3.617524529 13189.87342
3.2622068 13189.87342
3.287549515 13215.18987
3.645618702 13189.87342
4.011685905 12008.43882
4.407021164 10995.78059
4.81464642 10987.34177
5.242899398 11012.65823
5.693528961 10995.78059
6.187060849 21274.2616
6.668678978 23113.92405
7.201559268 22978.90295
7.762060463 23308.01688
8.376114784 22135.0211
9.031802606 22227.8481
9.740789702 22236.28692
10.50555399 22236.28692
11.35099655 22362.8692
12.27064187 22033.75527
13.33485712 22025.31646
14.53893529 30033.75527
15.88006029 30776.37131
17.53052302 30835.44304
19.58748291 30776.37131
22.25325616 30835.44304
26.13589008 30776.37131
33.61449307 30776.37131
44.62329613 30835.44304
29.93289682 30776.37131
24.44377745 30835.44304
21.14036795 30776.37131
18.74410116 30776.37131
16.89065642 30835.44304
15.35038336 30776.37131
14.10347698 26751.05485
12.91919234 22000
11.89893523 22168.77637
11.02040371 22295.35865
10.21148914 22303.79747
9.461912276 22261.60338
8.777003187 22270.04219
8.125495634 22438.81857
7.551896981 23139.24051
6.997299342 23215.18987
6.47436806 23071.72996
Lucas García
Lucas García le 29 Août 2011
Let me update my answer following this comment of yours...
KU
KU le 29 Août 2011
Hi,
This is a simple a question maybe! When I run your codes It has one error message as follows could you please let me how can i fix it,
??? Error using ==> set
Invalid root property: 'Rotation'
Thanks,
Lucas García
Lucas García le 29 Août 2011
Are you sure you are typing it correctly? Copy and paste this example. It should work fine.
X = rand(10,2);
plot(X(:,2))
set(gca, 'xTick', 1:size(X,1))
set(gca, 'xTicklabel','')
h = get(gca, 'XLabel');
set(h,'Units','data');
pos = get(h,'Position');
y = pos(2);
hLabels = zeros(1,size(X,1));
labels = num2str(X(:,1));
for i = 1:size(labels,1)
hLabels(i) = text(i,y,labels(i,:));
end
set(hLabels,'Rotation',45,'HorizontalAlignment','right')
KU
KU le 29 Août 2011
Thanks a lot Lucas, it works,

Connectez-vous pour commenter.

Plus de réponses (2)

Fangjun Jiang
Fangjun Jiang le 28 Août 2011
What effect do you want? You can always split them and plot them separately.
x=1:10;
y1=2*x+10;
y2=x.^2;
x=[x x];y=[y1 y2];
plot(x,y)
If you don't like the line from x=10 to x=1, replace the last line with,
plot(x,y,'r*');
To split:
idx1=1:10;
idx2=11:20;
figure;
plot(x(idx1),y(idx1),'r',x(idx2),y(idx2),'b');

1 commentaire

KU
KU le 29 Août 2011
Thanks for the reply, but it‘s not the proper graph for my work, actually I want to show effect of increasing value [1:10] and the decreasing value [10:1] in one figure. To this aim, the [10:1] values are located after [1:10].
I will be grateful if you give me any solution.

Connectez-vous pour commenter.

Walter Roberson
Walter Roberson le 29 Août 2011
x = 1:10;
plot(x, y1, x, y2)

1 commentaire

KU
KU le 29 Août 2011
Thanks, but as I added the above comment, the value are [1:10 10:10] and it is one curve.
P.S. I edited my question as well.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Object Properties dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by