在x轴上以八度为单位绘制日期:“错误:__ plt2vv__:矢量长度必须匹配". [英] Ploting dates on x-axis in octave: "error: __plt2vv__: vector lengths must match"

查看:327
本文介绍了在x轴上以八度为单位绘制日期:“错误:__ plt2vv__:矢量长度必须匹配".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在同一图上绘制3条线,并在X轴上显示日期.我可以完美地做到这一点,而无需在x轴上放置日期,但是当我尝试在x轴上放置年份时,会出现此错误:

I'm trying to plot 3 lines on the same figure with dates on X-axis . I can do it perfectly on without having dates on x-axis but when I try to put years on x-axis I get this error :

    error: __plt2vv__: vector lengths must match

我不熟悉MATLAB,这是我的第一个练习,这是我尝试绘制的代码部分:

I'm not familiar with MATLAB and this is my first tiral , here is the part of my code where I try to plot :

        data = importdata('2.txt');
        C = data.data.';
        C = C';

        N = length(C);
        H = 12;

        w = ones(2 * H + 1, 1);


       Lambda_Tilde = NaN * zeros(N, 1);
       L_Tilde = NaN * zeros(N, 1);
       U_Tilde = NaN * zeros(N, 1);
       for t = (H+1):(N-H-1)
          Lambda_Tilde(t) = sum(w .* C(t-H:t+H)) / sum(w);
          L_Tilde(t) = poissinv(0.005, Lambda_Tilde(t));
          U_Tilde(t) = poissinv(0.995, Lambda_Tilde(t));
       end



      clf
      f=figure();
      t= (1996 : 2007);
      dateFormat = 10;
      datetick('x',dateFormat)
      plot(datenum(t,1,1), C, 'co*');
      hold on
      plot(datenum(t,1,1) , L_Tilde, 'g-.');
      plot(datenum(t,1,1) , U_Tilde, 'g-.');
      pause;

现在我知道问题出在哪里了. C是1 * 144矩阵,因此有一种方法可以绘制

Now I understood where the problem is . C is a 1*144 Matrix, so is there a way to try to plot

     plot(1:N , C , 'co*' ) 

并且在xaxis上有日期,而不是随机数? 我将不胜感激任何指导.

and having dates on xaxis instead of having random numbers? I will appreciate any guidance .

推荐答案

我想您想做的就是更改t的形状,使它成为一个1x144矩阵,其中重复的日期(1996 12x,1997 12x等) .然后可以绘制(t,C),它应该可以工作.要更改形状,可以使用:

I think what you want to do is change the shape of t so that it is a 1x144 matrix with repeated dates in it (1996 12x, 1997 12x etc). Then you can plot(t,C) and it should work. To change the shape, you can use:

dates = [1996:2007];  %Creates the original dates matrix (your t)
N = size(dates,2);    %finds the length of that matrix (12 in your case)
M = 12;               %sets the number of repetitions
dates= repmat(dates,M,1);     %repeats each date M times, but they are still listed in columns
dates = reshape(dates,N*M,1); %changes the shape from columns containing the same shape to 1 column

这篇关于在x轴上以八度为单位绘制日期:“错误:__ plt2vv__:矢量长度必须匹配".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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