The graph I'm trying to create is empty

1 visualización (últimos 30 días)
Lothan Miranda
Lothan Miranda el 3 de Mzo. de 2021
Editada: KALYAN ACHARJYA el 3 de Mzo. de 2021
Hi,
I'm new to matlab and am struggling to plot a specicif graph. I'm trying to plot voltage against time. It starts at 50mV at 0s. After each msec, it increases by 15% as compared to its value 1 msec earlier. I tried a few appraoches and kept getting errors. I finally tried this approach with no errors but the graph is blank.
for t = 0:1:20
y = 50*1.15^t;
figure(1)
hold off
plot(t,y,'g')
title('Voltage vs Time')
xlabel('Time(ms)')
ylabel('voltage(mV)')
end

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 3 de Mzo. de 2021
Editada: KALYAN ACHARJYA el 3 de Mzo. de 2021
Here loop can be avoided (Recomended)
t = 0:1:20
y =50*1.15.^t;
figure,plot(t,y,'g')
title('Voltage vs Time')
xlabel('Time(ms)')
ylabel('voltage(mV)')
Using Loop: Read about the array, you need to store different y values ​​(with respect to invividual t).
t=0:1:20;
y=zeros(1,length(t)); % Preallocation memory
for i=1:length(t)
y(i)=50*1.15.^t(i);
end
plot(t,y,'g')
title('Voltage vs Time')
xlabel('Time(ms)')
ylabel('voltage(mV)')

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by