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

1 次查看(过去 30 天)
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