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

1 view (last 30 days)
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 Comments
Geoff Hayes
Geoff Hayes on 13 Sep 2014
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 on 15 Sep 2014
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

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!