从条形图中提取值时出错? [英] Error in extracting values from bar chart?

查看:70
本文介绍了从条形图中提取值时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

在此代码中,我绘制了条形图,我想从条形图中提取值. (正确地提取了值,但只画了一个点;没有画一条线)但是我得到了错误的结果. 我的目的是在

In this code I had plotted a bar chart and I want to extract values from bar chart. (Values are correctly extracted but only one point is plotted; not a line) But i'm getting wrong results. My aim is to plot a line between

                                 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列开始). 数字数量=列数

In first figure I need 2 lines(from 1 column); in second figure I need 2 lines(from 2 column); in third figure I need 2 lines(from 3 column) and in fourth figure I need 2 lines(from 4 column). no.of figures=no.of columns

版本2 我尝试了另一个版本

Version 2 I tried another version

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');

推荐答案

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);
figure; hold on;

for i = 1:size(d,2)
    x = [d(1,i) d(2,i)];
    y = [d(3,i) d(4,i)];
    plot(x,y);
end

要绘制一条线,必须确保plot(x,y)中的参数xy是矢量,而不是标量.例如,要在P1 = [P1x, P1y]P2 = [P2x, P2y]之间绘制一条线,参数应该为:

To plot a line, you must make sure the parameters x and y in plot(x,y) are vectors than scalars. For example, to plot a line between P1 = [P1x, P1y] and P2 = [P2x, P2y], the paramenters should be:

x = [P1x, P2x]; y = [P1y, P2y];

这篇关于从条形图中提取值时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆