Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 在对数基2比例上绘图_Matlab - Fatal编程技术网

Matlab 在对数基2比例上绘图

Matlab 在对数基2比例上绘图,matlab,Matlab,按照本文中的建议,我尝试绘制数据的log2值,并将水平轴和垂直轴上的刻度标签显示为2的幂。但是,我没有沿着两个轴获得所需的刻度标签。在两个轴上,我都希望记号标签显示为2的整数幂,即在x轴上:3和4,在y轴上:0,-1,-2,-3,-4和-5。这是我的密码: x = [ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ] Tcomm = [ 0.0357, 0.0515, 0.0745, 0.0956, 0.122, 0.1596, 0.2005,

按照本文中的建议,我尝试绘制数据的log2值,并将水平轴和垂直轴上的刻度标签显示为2的幂。但是,我没有沿着两个轴获得所需的刻度标签。在两个轴上,我都希望记号标签显示为2的整数幂,即在x轴上:3和4,在y轴上:0,-1,-2,-3,-4和-5。这是我的密码:

x = [ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
Tcomm = [ 0.0357, 0.0515, 0.0745, 0.0956, 0.122, 0.1596, 0.2005, 0.2443, 0.2873, 0.3752, 0.4148, 0.5102, 0.5882 ]
plot(log2(x), log2(Tcomm), 'ko')
set(gca, 'XTickLabel',[])                      %# suppress current x-labels
xlim([log2(8),log2(16)])
xt = get(gca, 'XTick');
yl = get(gca, 'YLim');
str = cellstr( num2str(xt(:),'2^{%d}') );      %# format x-ticks as 2^{xx}
hTxt = text(xt, yl(ones(size(xt))), str, ...   %# create text at same locations
'Interpreter','tex', ...                   %# specify tex interpreter
'VerticalAlignment','top', ...             %# v-align to be underneath
'HorizontalAlignment','center');           %# h-aligh to be centered

xlabel('N');
ylim([log2(0.0357), log2(0.58825)])
set(gca, 'YTickLabel',[])
xt = get(gca, 'YTick');
yl = get(gca, 'XLim');
str = cellstr( num2str(xt(:),'2^{%d}') );      %# format x-ticks as 2^{xx}
hTxt = text(xt, yl(ones(size(xt))), str, ...   %# create text at same locations
'Interpreter','tex', ...                   %# specify tex interpreter
'VerticalAlignment','middle', ...             %# v-align to be underneath
'HorizontalAlignment','right');           %# h-aligh to be centered

ylabel('CommunicationTime');
title('(a)');

对于Y轴部件,在text命令中,只需交换第一个值和第二个值:

xlabel('N');
ylim([log2(0.0357), log2(0.58825)])
set(gca, 'YTickLabel',[])
xt = get(gca, 'YTick');
yl = get(gca, 'XLim');
str = cellstr( num2str(xt(:),'2^{%d}') );      %# format x-ticks as 2^{xx}
hTxt = text( yl(ones(size(xt))),xt, str, ...   %# create text at same locations
'Interpreter','tex', ...                   %# specify tex interpreter
'VerticalAlignment','middle', ...             %# v-align to be underneath
'HorizontalAlignment','right');           %# h-aligh to be centered

您的
x
数据中只有两个2的整数幂,8和16。您想要的刻度标签是什么
xt
包含带有
.5
的值,但您尝试打印带有
%d
的整数。右,在x轴上,仅3和4。在y轴上:0,-1,-2,-3,-4,-5