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

 Respuesta aceptada

the cyclist
the cyclist el 21 de Nov. de 2020
Editada: the cyclist el 21 de Nov. de 2020

0 votos

Put the command
hold on
on the line after figure.

Más respuestas (1)

Setsuna Yuuki.
Setsuna Yuuki. el 21 de Nov. de 2020
Editada: Setsuna Yuuki. el 21 de Nov. de 2020

0 votos

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 comentarios

Khang Nguyen
Khang Nguyen el 21 de Nov. de 2020
this is what the out put says for me "Array indices must be positive integers or logical values." on line 9
the cyclist
the cyclist el 21 de Nov. de 2020
vectori is not used in the rest of the code. I commented it out completely, and the code runs.
Setsuna Yuuki.
Setsuna Yuuki. el 21 de Nov. de 2020
I edited my answer, now this works :D
Khang Nguyen
Khang Nguyen el 21 de Nov. de 2020
lovely: thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Graph and Network Algorithms en Centro de ayuda y File Exchange.

Preguntada:

el 21 de Nov. de 2020

Comentada:

el 21 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by