MATLAB Answers

Index exceeding number of array elements on second iteration of loop

조회 수: 1(최근 30일)
Thomas Sibly
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:
DELTA_plot = DELTA_initial;
P_plot = Prl_in;
title('Plot of Load (P) - Global Deformation (Δ) Relationship')
xlabel('Deformation Δ (mm)')
ylabel('Load P (kN)')
plot(DELTA_plot(c),P_plot(c),'.'); hold on;
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.


Mathieu NOE
Mathieu NOE 2021년 8월 31일
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 :
DELTA_plot(c) = DELTA_initial;
P_plot(c) = Prl_in;
  댓글 수: 2
Mathieu NOE
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 ?

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




Community Treasure Hunt

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

Start Hunting!

Translated by