1 view (last 30 days)

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.

Hiro
on 30 Mar 2020

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):

Opportunities for recent engineering grads.

Apply Today
## 13 Comments

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817670

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817670

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817681

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817681

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817687

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817687

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817691

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817691

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817692

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817692

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817728

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_817728

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818195

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818195

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818199

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818199

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818202

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818202

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818203

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818203

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818917

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818917

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818985

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_818985

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_823441

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/513844-index-exceeds-the-number-of-array-elements-when-trying-to-plot#comment_823441

Sign in to comment.