# Index exceeding number of array elements on second iteration of loop

조회 수: 1(최근 30일)
Thomas Sibly 2021년 8월 31일
편집: Walter Roberson 2021년 9월 1일
Apologies if this has been answered previously but I could not see an answer specific to my case. Im modelling the damage properties properties over a number of cycles (c). Theres a number of while loops within while loops if that makes any difference.
A single point is itervatively solved (DELTA_plot,P_plot) if:
if(length==Sp)
if(abs(ddelta_dx(y))<tol&&abs(DELTA(y))<tol)
DELTA_plot = DELTA_initial;
P_plot = Prl_in;
end
figure(1)
title('Plot of Load (P) - Global Deformation (Δ) Relationship')
xlabel('Deformation Δ (mm)')
plot(DELTA_plot(c),P_plot(c),'.'); hold on;
grid
This works for the first cycle (c=1), which plots a linear relationship. However when I repeat the exact same code for the second cycle, with different initial parameters, the following error appears:
"Index exceeds the number of array elements (1)."
plot(DELTA_plot(c),P_plot(c),'.'); hold on;
What am I doing wrong? If i try to plot as follow:
plot(DELTA_plot,P_plot,'.'); hold on;
It does not plot correctly.
Please let me know if you require any additonal information and thanks for any help.

댓글을 달려면 로그인하십시오.

### 답변(1개)

Mathieu NOE 2021년 8월 31일
hello
your variables are not indexed , so this is no surprise that it will fail at the second iteration
code should be , assuming c is the current loop index :
if(abs(ddelta_dx(y))<tol&&abs(DELTA(y))<tol)
DELTA_plot(c) = DELTA_initial;
P_plot(c) = Prl_in;
end
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Mathieu NOE 2021년 9월 1일
well , I don't know what your code is supposed to do and what size are variables DELTA_initial and Prl_in and if their size is constant or not as you loop ?
what size are you expecting the result DELTA_plot and P_plot to be ?
are you willing to share the entire code ?

댓글을 달려면 로그인하십시오.

R2021a

### Community Treasure Hunt

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

Start Hunting!