Reputation: 67
I have a positive natural number vector which I am plotting in Matlab using the typical plot() function. Here is a sample plot:
However, I need to see the vector (y axis) displayed in binary. Is there a way to change the axis display in binary (radix-2) ? I tried using dec2bin, but it only converts the integers to strings which can not be plotted.
Upvotes: 1
Views: 1083
Reputation: 1824
How about this:
L = get(gca,'YTickLabel');
set(gca,'YTickLabel',cellfun(@(x) dec2bin(str2num(x)),L,'UniformOutput',false));
edit: Since you wanted the ability to zoom, here is a way to make the axis zoomable:
zh = zoom(gcf);
set(zh,'ActionPreCallBack',@(source,event,s) set(gca,'YTickLabelMode','auto'))
set(zh,'ActionPostCallBack',@(source,event,s) set(gca,'YTickLabel',cellfun(@(x) dec2bin(str2num(x)),get(gca,'YTickLabel'),'UniformOutput',false)));
It resets the axis to decimal before the zoom and then converts back to binary after the zoom.
Upvotes: 3