code loop occur errors
3 次查看(过去 30 天)
显示 更早的评论
m = 0.5;
g = 9.81;
F = m*g;
theta = 0:50
V = sqrt(2*F/m);
vertical = V*sin(theta);
pve = V_hi > 0;
t_pve = theta(pve);
for i = 1:length(V_vi)
for j = 1:length(t_pve)
j = j+1;
while vertical(i) > 4.65
vertical(i) = Vertical_new;
end
end
end
I wanna obtain all the Vertical_new which satisfied the while loop condition, why it won't run? This is the error shown
Unrecognized function or variable 'Vertical_new'
9 个评论
dpb
2022-5-20
...
for i = 1:length(V_vi)
for j = 1:length(t_pve)
j = j+1;
while vertical(i) > 4.65
vertical(i) = Vertical_new;
end
end
end
Besides the other comments, there's nothing inside the loop over j that is dependent upon what j is; it simply repeats the same assignment of i element of array length(t_pve) times.
Secondly, you try to change the loop indexing variable j each time inside the loop -- this is not kosher; see the documentation for for that has an explanation/note about it. Even if it were used, the loop construct would reset it to the loop counter value each pass through the loop, anyway...
Thirdly, you referenced a variable V_hi that looks to have been intended to be the height against to test; but as others noted, it's not defined. Assign it the value of the constant and don't bury "magic" numbers of that sort in the code; use variables that can be changed easily/documented.
回答(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!