Define a variable?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I want to plot n spheres. Its working but the variable k is always red underlined because I didnt defined it before the loop. How can I define this variable?
for i = 1:n
k(i) = surf(r*x+p(i,1),r*y+p(i,2),r*z+r);
end
0 个评论
采纳的回答
SungJun Cho
2021-6-17
The red underline occurs when you have not preallocated your array (or matrix).
You can just do
k = zeros(1,n);
for i = 1:n
k(i) = surf(r*x+p(i,1),r*y+p(i,2),r*z+r);
end
and this should solve your problem.
更多回答(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!