how to graph using loop?
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
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
Khang Nguyen
2020년 11월 21일
the cyclist
2020년 11월 21일
vectori is not used in the rest of the code. I commented it out completely, and the code runs.
Setsuna Yuuki.
2020년 11월 21일
I edited my answer, now this works :D
Khang Nguyen
2020년 11월 21일
카테고리
도움말 센터 및 File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!