Putting for loop values into a matrix/array for plotting
显示 更早的评论
I am trying to find the optimum length of a bridge with regards to cost. I'm trying to put the values from each loop into an array/matrix so I can then find the correspoding road and bridge lengths for the lowest cost on each cost ratio, however the answers from each loop are "seperate" from all other loops and I need them in one array. Does anyone know if this is possible, and if so how I would be able to do this I'm struggling to figure out how it can be done. Thanks.
Ly = 8.7 %total length ravine
Lx = 1.1 %width of ravine
Cs = 1e6 %cost of road per km
for r = 1.1:0.5:5 %varying ratio between road cost per km and bridge cost per km
Ls = 0.1:0.1:8.6; %varying length of road
Lb = sqrt((Ly-Ls).^2 + Lx.^2); %equation to find length of bridge from the length of road
C =((r*Cs)*(Lb))+(Cs*Ls); %equation for total cost of bridge and road
min(C) %minimum value of C for each ratio loop
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!