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.
댓글 수: 16
Cris LaPierre
2020년 3월 30일
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
2020년 3월 30일
편집: Asadullah Khalid
2020년 3월 30일
Asadullah Khalid
2020년 3월 30일
편집: Asadullah Khalid
2020년 3월 30일
Walter Roberson
2020년 3월 30일
L(2)=plot(x(1:length(y2), y2, 'b', 'LineWidth', 1.5);
Asadullah Khalid
2020년 3월 30일
편집: Asadullah Khalid
2020년 3월 30일
Walter Roberson
2020년 3월 30일
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
2020년 3월 30일
편집: Asadullah Khalid
2020년 3월 30일
Image Analyst
2020년 3월 30일
Did I miss where you attached your data? ?♂️ People can't try anything without it.
Asadullah Khalid
2020년 3월 30일
편집: Asadullah Khalid
2020년 3월 30일
Asadullah Khalid
2020년 3월 30일
Asadullah Khalid
2020년 3월 31일
Walter Roberson
2020년 4월 1일
I have been quite busy lately :(
Asadullah Khalid
2020년 4월 8일
Adam Danz
2020년 10월 2일
"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
2020년 10월 3일
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
2020년 10월 8일
(Answers Dev) Restored edit
답변 (1개)
Hiro Yoshino
2020년 3월 30일
0 개 추천
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):
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
