Using a Nested For Loop with input from an Array to Create an Array
显示 更早的评论
Hello all,
I am trying to use the code seen below to output an array titled as "Fatigue_Life" when the function of "mancof" changes from positive to negative. The input of j should be for each variable in the "de" array and the output should be an array for the value of i at which the "mancof" function becomes negative. The output array should be the exact same dimension as the input array. For example, de(1,1)=0.00486 should result in Fatigue_Life(1,1)=72 and so on until the array has been fully calculated. The code currently runs but I can not seem to get the output matrix as described above it seems to just be taking the last value? I created the input array "de" of all the same values for simplicity so the output array should also be of the same value, known to be 72. I hope what I would like to happen is clear. Please see the code below, any help will be greatly appreciated.
MATLAB Code:
clc
clear
E=75657;
ef=.057429;
sf=227.365;
b=-0.0787879;
c=-0.6060601;
t=.00486;
de= t.*ones(1,100);
mancof=(sf/E*(2*i)^b)+(ef*(2*i)^c)-de;
Fatigue_Life=0;
for i=1:length(de)
for j=de(:,i)
if mancof>0
mancof=(sf/E*(2*i)^b)+(ef*(2*i)^c)-j;
Fatigue_Life=i
elseif mancof<0
fprintf('The Fatigue Life is: \n', Fatigue_Life)
end
end
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!