Index exceeding number of array elements on second iteration of loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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)')
ylabel('Load P (kN)')
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.
댓글 수: 0
답변 (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
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 ?
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!