Index exceeds the number of array elements, when trying to plot

1 回表示 (過去 30 日間)
Asadullah Khalid
Asadullah Khalid 2020 年 3 月 30 日
コメント済み: Rena Berman 2020 年 10 月 8 日
I am trying to plot multiple plots on a common x-axis. The problem that I am facing is that the size of my data sets (data1, and data2) are different from each other. Also, the length of the data to be used for x-axis is same as data2, but not data1.
This is resulting into the following error:
Index exceeds the number of array elements (683898).
Error in Plot_code
y1 = y1(dum)
data1= Test180diffcap;
data2= Test192diffcap;
data4= timediffcap;
y1=data1{:,1};
y2=data2{:,1};
x=data4{:,1};
[x, dum] = sort(x);
y1 = y1(dum);
[x, dum2] = sort(x);
y2 = y2(dum2);
L(1)=plot(x,y1, 'k','LineWidth',1.5);
hold on
L(2)=plot(x,y2, 'b','LineWidth',1.5);
Any suggestion to resolve this error would be highly appreciated.
  16 件のコメント
Rik
Rik 2020 年 10 月 3 日
Original post by Asadullah Khalid retrieved from Google cache:
Index exceeds the number of array elements, when trying to plot
I am trying to plot multiple plots on a common x-axis. The problem that I am facing is that the size of my data sets (data1, and data2) are different from each other. Also, the length of the data to be used for x-axis is same as data2, but not data1.
This is resulting into the following error:
Index exceeds the number of array elements (683898).
Error in Plot_code
y1 = y1(dum)
data1= Test180diffcap;
data2= Test192diffcap;
data4= timediffcap;
y1=data1{:,1};
y2=data2{:,1};
x=data4{:,1};
[x, dum] = sort(x);
y1 = y1(dum);
[x, dum2] = sort(x);
y2 = y2(dum2);
L(1)=plot(x,y1, 'k','LineWidth',1.5);
hold on
L(2)=plot(x,y2, 'b','LineWidth',1.5);
Any suggestion to resolve this error would be highly appreciated.
Rena Berman
Rena Berman 2020 年 10 月 8 日
(Answers Dev) Restored edit

サインインしてコメントする。

回答 (1 件)

Hiro Yoshino
Hiro Yoshino 2020 年 3 月 30 日
Why not reampling the data to have the same length?
If you have Signal Processing toolbox, then just follow the instruction:
Also interpolation might work as well (available from MATLAB itself):
  1 件のコメント
Asadullah Khalid
Asadullah Khalid 2020 年 3 月 30 日
I think that I will lose the originality of the data, that I am trying to visualize if I perform sampling.
And I think the interpolation would just add a datapoint from the last values in Test192diffcap and Test180diffcap, but I am actually trying to visualize the data as is.
Please correct me if I understood incorrectly.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by