Fixing the x ticks for a plot

2 次查看(过去 30 天)
Raza
Raza 2019-4-4
I have a variable named 'a' of the size 20x40 double and I am trying to plot it. At first I ploted it, without specifying the tick values and Matlab is generating the auto ticks for me. Now, I want to take those ticks and multiply it with a constant and update the previous ticks with the new ones.
I approached it using two ways but both the codes have some flaw to them.
1) In this code I am trying to multiply a constant with the old ticks and then updating it with the new ticks but the xtick values don't make sense. They appear right in the workspace but they dont show up correctly on the plot.
xticks = get(gca,'xtick'); % reads old x ticks
constant = 0.25;
new_Xticklabels = arrayfun(@(x) sprintf('%.0f', constant * x), xticks, 'un', 0);
set(gca,'xticklabel',new_Xticklabels);
yticks = get(gca,'ytick'); %reads old y ticks
new_Yticklabel=arrayfun(@(y) sprintf('%.0f', constant * y), yticks, 'un', 0);
set(gca,'yticklabel',new_Yticklabel);
2)In the second code I tried to specify the x and the y ticks and used the labels to show the value but in doing that the graph shows up with empty spots.
xticks([12 20 32 40]);
xticklabels({'3','5','8','10'});
yticks([8 16 24 32 40 48 56 64]);
yticklabels({'2','4','6','8','10','12','14','16'});
Any help would be appreciated.
Thank you.
  4 个评论
Walter Roberson
Walter Roberson 2019-4-4
Both versions appear to work for me.
Agnish Dutta
Agnish Dutta 2019-4-12
The first version seems to be working fine.
The second one may be giving problems because the of values you are specifying as input to the "xticks" function may be out of the range.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by