Fixing the x ticks for a plot
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!