フィルターのクリア

“plot” function for some repetitive X values

1 回表示 (過去 30 日間)
KU
KU 2011 年 8 月 28 日
編集済み: Deepak Sharma 2021 年 5 月 25 日
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 件のコメント
Deepak Sharma
Deepak Sharma 2021 年 5 月 25 日
編集済み: Deepak Sharma 2021 年 5 月 25 日
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.

サインインしてコメントする。

採用された回答

Lucas García
Lucas García 2011 年 8 月 29 日
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 件のコメント
Lucas García
Lucas García 2011 年 8 月 29 日
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 2011 年 8 月 29 日
Thanks a lot Lucas, it works,

サインインしてコメントする。

その他の回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 28 日
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 件のコメント
KU
KU 2011 年 8 月 29 日
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.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2011 年 8 月 29 日
x = 1:10;
plot(x, y1, x, y2)
  1 件のコメント
KU
KU 2011 年 8 月 29 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by