how to graph using loop?

1 次查看(过去 30 天)
I want to calculate a problem and graph it
I want to graph i and area but it only show one point on my graph
% question1
clear all
a = 1
vectori = []
areavec = []
figure;
for i = 0:20
a = a + a
area = a *(1/8).^i
scatter(i,area)
end

采纳的回答

the cyclist
the cyclist 2020-11-21
编辑:the cyclist 2020-11-21
Put the command
hold on
on the line after figure.

更多回答(1 个)

Setsuna Yuuki.
Setsuna Yuuki. 2020-11-21
编辑:Setsuna Yuuki. 2020-11-21
You must change this:
clear all
a = 1
vectori = []% ??
areavec = []
figure;
for i = 0:20
a = a + a
areavec(i+1) = a *(1/8).^i %area --> areavec and areavec is a vector, not a scalar
end
i = 0:20;
scatter(i,areavec) %area --> areavec and graph must be out of cycle
  4 个评论
Setsuna Yuuki.
Setsuna Yuuki. 2020-11-21
I edited my answer, now this works :D

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by