My script is working wrong with nested for loops
显示 更早的评论
d = input('enter a number:')
figure
for b = 0:0.5:d
plot(b, 0, '*k')
pause(0.05)
end
for c = 0:0.5:d
plot(0, c, '*k')
plot(d, c, '*k')
pause(0.05)
end
for b = 0:0.5:d
plot(c, d, '*k')
pause(0.05)
end
I couldn't run this script nested for-end loops. How can I do that? It is working correct like this. I want to make lines thinner. I couldn't use Linewidht correctly probably. Can I use axes command differently or use something else?
3 个评论
Jan
2021-3-24
There are no nested loops in this code. "Nested" would be:
for i1 = 1:10
for 12 = 1:10
...
end
end
How do "I couldn't run this script" and "It is working correct like this" match?
"I want to make lines thinner." - how did you try this? Post the code, which is failing, not some other code, which is running.
"Can I use axes command differently" - yes, of course. Differently then what?
sky2
2021-3-24
Jan
2021-3-24
But there are no nested loops and no need for nested loops. If you have a problem with some code, which contain nested loops, post this code and explain the problems.
采纳的回答
更多回答(1 个)
Jan
2021-3-24
Plotting the line does not need a loop:
% for b = 0:0.5:a % The body does not depend on b, so omit the loop
plot([0, a, a, 0, 0], [0, 0, a, a, 0], '-k')
% end
What is the problem with which line width?
plot([0, a, a, 0, 0], [0, 0, a, a, 0], '-k', 'LineWidth', 3)
3 个评论
DGM
2021-3-24
oof. I didn't even catch that.
sky2
2021-3-24
Jan
2021-3-24
"use hold on instead of using axes" - this is not meaningful. hold on sets the NextPlot property of the axes to 'add'. You can do this directly also.
You can either define the MarkerSize inside each plot command, or as default in the axes object. It is a question of taste.
类别
在 帮助中心 和 File Exchange 中查找有关 Geographic Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!