Index exceeds the number of array elements, when trying to plot
Mostrar comentarios más antiguos
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 comentarios
Cris LaPierre
el 30 de Mzo. de 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
el 30 de Mzo. de 2020
Editada: Asadullah Khalid
el 30 de Mzo. de 2020
Asadullah Khalid
el 30 de Mzo. de 2020
Editada: Asadullah Khalid
el 30 de Mzo. de 2020
Walter Roberson
el 30 de Mzo. de 2020
L(2)=plot(x(1:length(y2), y2, 'b', 'LineWidth', 1.5);
Asadullah Khalid
el 30 de Mzo. de 2020
Editada: Asadullah Khalid
el 30 de Mzo. de 2020
Walter Roberson
el 30 de Mzo. de 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
el 30 de Mzo. de 2020
Editada: Asadullah Khalid
el 30 de Mzo. de 2020
Image Analyst
el 30 de Mzo. de 2020
Did I miss where you attached your data? ?♂️ People can't try anything without it.
Asadullah Khalid
el 30 de Mzo. de 2020
Editada: Asadullah Khalid
el 30 de Mzo. de 2020
Asadullah Khalid
el 30 de Mzo. de 2020
Asadullah Khalid
el 31 de Mzo. de 2020
Walter Roberson
el 1 de Abr. de 2020
I have been quite busy lately :(
Asadullah Khalid
el 8 de Abr. de 2020
Adam Danz
el 2 de Oct. de 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
el 3 de Oct. de 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
el 8 de Oct. de 2020
(Answers Dev) Restored edit
Respuestas (1)
Hiro Yoshino
el 30 de Mzo. de 2020
0 votos
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 comentario
Asadullah Khalid
el 30 de Mzo. de 2020
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
