在 matlab 图中的单元格的 for 循环图中设置图例
当我尝试为 for 循环图创建图例时,我需要您的帮助来解决我遇到的问题。我使用的代码如下,
for i=3:14
plot(data(:,i),data(:,2));
hold all;
end
legend(textdata{1,3:14});
texdata 是一个 1x14 单元格,其中存储了我想要使用的图例的名称。 当我运行脚本时,我得到了绘图,但我收到的不是图例,而是错误消息“???索引超出矩阵尺寸。”
编辑:我添加了 whos textdata
答案,因为我无法在评论答案中以良好的方式编写它
>> whos textdata
Name Size Bytes Class Attributes
textdata 1x14 1652 cell
I need your help to solve a problem i am facing when i am trying to create a legend to a for loop plot. The code i am using is the following
for i=3:14
plot(data(:,i),data(:,2));
hold all;
end
legend(textdata{1,3:14});
texdata is a 1x14 cell
where they are stored the names of the legends i want to use.
When i am running my script, i get the plot but instead of legend i am getting this error message "??? Index exceeds matrix dimensions."
edit: i add the whos textdata
answer, because i can't write it in a good way on comment answer
>> whos textdata
Name Size Bytes Class Attributes
textdata 1x14 1652 cell
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用这段代码对我来说效果很好。文本数据中每个字符串的长度应该无关紧要。
如果错误仅出现在图例添加上,您就知道这是文本数据的问题。尽管我认为您的绘图工作正常?
您确定您的文本数据已正确存储吗?文本数据的维度可能与您想要绘制的数据不同。
尝试运行 whos 就像评论所说:
编辑:评论在我写答案时已更新......
This worked fine for me using this code. The length of each string in textdata should not matter.
If the error only comes up on the legend addition you know it is a problem with textdata.. Your plot works fine though I assume?
Are you sure your textdata is stored appropriately? It is likely that textdata is, well, of different dimensions than what you are trying to plot.
Try running whos like the comment says:
edit: comments were updated while I wrote the answer...