Changing variable value after each loop interation and store them in array
2 次查看(过去 30 天)
显示 更早的评论
I'm trying to store values in array xx and for each new loop iteration (i) i want the values divided by (j) to get stored in a new column (k).
My problem is that the (j) don't change for each new loop iteration and i get the same values for the entire array.
any one know how to solve this?
I want the variable 1/j in the first column to be j=0.01 and for the second column j=0.02 etc.
for i= 1:1:61
for k=1:1:8
for j=0.01:0.01:0.08
xx(i,k) = nthroot(Q(i)/((1/j)*B*(S0^(1/2))),5/3);
end
end
end
result
xx =
0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841
0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841
0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841
0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841
0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841
0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841
0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841 0.7841
0.8302 0.8302 0.8302 0.8302 0.8302 0.8302 0.8302 0.8302
0.8747 0.8747 0.8747 0.8747 0.8747 0.8747 0.8747 0.8747
0.9177 0.9177 0.9177 0.9177 0.9177 0.9177 0.9177 0.9177
0.9594 0.9594 0.9594 0.9594 0.9594 0.9594 0.9594 0.9594
1.0000 1.0000 ...
Cheers!
0 个评论
采纳的回答
Roger Wohlwend
2016-2-26
for i=1:61
for k=1:8
xx(i,k) = nthroot(Q(i)/((100/k)*B*(S0^(1/2))),5/3);
end
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 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!