【发布时间】:2017-05-03 01:53:51
【问题描述】:
d=[1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16]
bar_widh=0.2;
figure;
h = bar(d,bar_widh);
for i=1:2:4
for j=1:4
x=d(i,j)
y=d(i+1,j)
figure,plot(x,y);
end
i=i+1;
end
在这段代码中,我绘制了一个条形图,我想从条形图中提取值。 (正确提取了值,但只绘制了一个点;不是一条线)但是我得到了错误的结果。 我的目标是在
之间画一条线 d(1,1) and d(2,1);d(3,1) and d(4,1);
d(1,2) and d(2,2);d(3,2) and d(4,2);
d(1,3) and d(2,3);d(3,3) and d(4,3);
d(1,4) and d(2,4);d(3,4) and d(4,4);
在第一个图中,我需要 2 行(来自 1 列);在第二个图中,我需要 2 行(来自 2 列);在第三个图中我需要 2 行(来自 3 列),在第四个图中我需要 2 行(来自 4 列)。 no.of 数字=no.of 列
第 2 版 我尝试了另一个版本
d=[1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16]
bar_widh=0.2;
figure;
h = bar(d,bar_widh);
saveas(h,'testfigure.fig');
clear
close all
h=hgload('testfigure.fig');
ch=get(h,'Children');
l=get(ch,'Children');
x=get(l,'Xdata');
y=get(l,'Ydata');
我收到错误
Error using get
Conversion to double from cell is not possible.
Error in Untitled5 (line 10)
l=get(ch,'Children');
【问题讨论】:
-
您应该将
figure移到for循环之外并在其后放置hold on:figure; hold on; for i = 1:2:4。您可能需要将plot(x,y)更改为plot(x,y,'*'),否则您将很难看到您绘制的内容。 -
说实话,你的问题质量很低。我不知道你到底想达到什么。好的,我知道您想使用条形图中的数据绘制一些线,但是哪些线?你希望线条看起来像什么?您不能只是假设人们会理解您对线的定义并帮助您解决问题。
-
您收到错误,因为
ch不包含图形句柄,但您使用它时就像它包含一个句柄一样。 -
感谢您的澄清。现在看起来好多了。那么,我可以假设
d(1,1) and d(2,1);d(3,1) and d(4,1);表示点(d(1,1), d(2,1))和(d(3,1), d(4,1))之间的一条线吗?这意味着你需要四行? -
是的。在第一个图中我需要 2 行(来自 1 列)。在第二个图中我需要 2 行(来自 2 列);在第三个图中我需要 2 行(来自 3 列),在第四个图中我需要 2 行(来自 4 列).no.of figure=no.of columns