How can I use elements of a vector for the '' for loop '' ?

조회 수: 1 (최근 30일)
ITU
ITU 2014년 9월 12일
댓글: ITU 2014년 9월 15일
I want to code some simple formulas for the ultimate strength calculation of ship panels. I have coded nested for loop in a function. Inner loop uses elements of a vector as loop boundary. But in this case, it gives some incorrect results. Related part of my code is attached. In my code N is a vector whose dimension is kx1. I have to use every single element of N vector as boundary for inner loop. Other vectors have been calculated previously.
Thank you so much in advance.
Best Regards.
Murat
  댓글 수: 7
Geoff Hayes
Geoff Hayes 2014년 9월 13일
So what value does the code read if not the intended N(i)? Please add the following line of code as the first line in the inner for loop
fprintf('N(i)=%d i=%d j=%d\n',N(i),i,j);
Just have the code run for the first handful of i (maybe 1 through to 5 or so) and observe the output of the above fprintf. Paste it back here and indicate what the code should read versus what it is reading.
ITU
ITU 2014년 9월 15일
Dear Hayes,
The problem has been solved, the problem is not about N(i) but about dimensions of yi(j), Lcr2(j) and Lcr3(j). N(i) > N(i+1) is some cases, so new iteration writes the new vector over the previos one. Finally, summation of elements of these vector gives undesired values. Thank you so much for your nice support.
Best Regards.
Murat

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by