Matlab绘图中的传奇

时间:2014-05-17 00:47:27

标签: matlab plot

我的传说有些问题。我试图使用此代码绘图,代码是这样的:

function PlotNormalPlot(z,i)
hold on
plotTypes = {'b', 'm', 'c'};
TrancheRange = {'100','1000','10000'};
h = normplot(z);
set(h,'color',plotTypes{i})
xlabel('Estimate')
ylabel('Probability')
legendInfo{i} = TrancheRange{i};
legend(legendInfo);
end

它给了我这个错误:

Error using legend>process_inputs (line 552)
Cell array argument must be a cell array of strings.

不确定为什么会出现此错误?需要一些指导。

编辑:

当我尝试这个时:

function PlotNormalPlot(z,i)
hold on
plotTypes = {'b', 'm', 'c'};
TrancheRange = {'100','1000','10000'};
h = normplot(z);
set(h,'color',plotTypes{i})
xlabel('Estimate')
ylabel('Probability')
%legendInfo = TrancheRange{i};
legend(TrancheRange);
end

传说很好,但颜色没有附加到图例上。不知道为什么。

现在看起来像这样:enter image description here

1 个答案:

答案 0 :(得分:0)

尝试legendInfo=TrancheRange{i},因此legendInfo是一个字符串。

legendInfo{i}会创建一个单元格数组,例如,对于i=2,它会给你legendInfo={[] '2'},其中legendInfo的第一个元素是一个空数组。< / p>


我认为这可以回答你的第二个问题。它使用绘图句柄保存图例信息:

h = normplot(z);
set(h,'color',plotTypes{i},'DisplayName',TrancheRange{i})
legend(h,'show')