Index exceeds the number of array elements, when trying to plot
Afficher commentaires plus anciens
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 commentaires
Cris LaPierre
le 30 Mar 2020
Perhaps we could be of more help if you tell us what it is you are trying to do. Why do you sort x? Why does Test192diffcap have more values? How do the values in Test180diffcap and Test192diffcap relate to the rows in Timediffcap?
Asadullah Khalid
le 30 Mar 2020
Modifié(e) : Asadullah Khalid
le 30 Mar 2020
Asadullah Khalid
le 30 Mar 2020
Modifié(e) : Asadullah Khalid
le 30 Mar 2020
Walter Roberson
le 30 Mar 2020
L(2)=plot(x(1:length(y2), y2, 'b', 'LineWidth', 1.5);
Asadullah Khalid
le 30 Mar 2020
Modifié(e) : Asadullah Khalid
le 30 Mar 2020
Walter Roberson
le 30 Mar 2020
data1= Test180diffcap;
data2= Test192diffcap;
data4= timediffcap;
y1=data1{:,1};
y2=data2{:,1};
x=data4{:,1};
[x1, dum] = sort(x1);
y1 = y1(dum);
ny2 = length(y2);
[x2, dum2] = sort(x(1:ny2));;
y2 = y2(dum2);
L(1)=plot(x1, y1, 'k','LineWidth',1.5);
hold on
L(2)=plot(x2, y2, 'b','LineWidth',1.5);
Asadullah Khalid
le 30 Mar 2020
Modifié(e) : Asadullah Khalid
le 30 Mar 2020
Image Analyst
le 30 Mar 2020
Did I miss where you attached your data? ?♂️ People can't try anything without it.
Asadullah Khalid
le 30 Mar 2020
Modifié(e) : Asadullah Khalid
le 30 Mar 2020
Asadullah Khalid
le 30 Mar 2020
Asadullah Khalid
le 31 Mar 2020
Walter Roberson
le 1 Avr 2020
I have been quite busy lately :(
Asadullah Khalid
le 8 Avr 2020
Adam Danz
le 2 Oct 2020
"Moderators, Kindly delete this question. Did not help me in posting the question here. If I have the option to delete which I'm unaware of, please advise."
there's no guarantee that questions will get a working solution in this forum. Common barricades that get in the way of finding a solution are
- Not enough information to identify or solve the problem
- Idiosyncrasies that are very difficult to address remotely
- Improper application of viable solutions or lack of cooperation to attempt the solutions
- Lack of interest or background knownlege by volunteers who answer questions
By posting a question, you are asking mostly unpaid volunteers to give their time to address your question and help you. Comments and answers often help countless individuals looking for similar solutions as evidenced by the 30-day view counts on threads that are years old. Deleting content is disrespectful to those who have invested their time to help you and the general community.
Please review
Rik
le 3 Oct 2020
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
le 8 Oct 2020
(Answers Dev) Restored edit
Réponses (1)
Hiro Yoshino
le 30 Mar 2020
0 votes
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 commentaire
Asadullah Khalid
le 30 Mar 2020
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
