Array reverting to 0 when called

I have an array generated by ode45. When I try to graph one of the columns, the column turns into all near-zero values, despite displaying correctly when I call individual values of the column. The other columns work correctly. Here is my code, xa(:,2) works correctly but xa(:,1) does not.
load proj3data.txt;
a = proj3data(:,1);
b = proj3data(:,2)+proj3data(:,3);
c = proj3data(:,4);
f = @(t,x) [-500*x(1)*x(2)+1*x(3);500*x(1)*x(2) - 0.5*x(2);0.5*x(2)*x(1)-1*x(3)];
[t,xa] = ode45(f,[0 15],[732 1 0]);
figure(1)
plot(t,xa(:,1))
hold on
scatter(a,b)
hold off;
figure(2)
plot(t,xa(:,2))
hold on
scatter(a,c);

Respuestas (1)

Star Strider
Star Strider el 2 de Abr. de 2019

0 votos

Providing that none of your ‘xa’ values are negative or zero, use semilogy instead of plot.

4 comentarios

Leah Shein
Leah Shein el 2 de Abr. de 2019
This just gives me a graph of the same incorrect values on a different scale. Just displaying the column gives me all zeros, even though when I open the variable it shows the correct values. It doesn't seem to be a problem with the graphing.
Use this to plot them to see that they’re not all zero:
figure
subplot(3,1,1)
loglog(t, xa(:,1))
grid
subplot(3,1,2)
loglog(t, xa(:,2))
grid
subplot(3,1,3)
loglog(t, xa(:,3))
grid
Note that you will get a ‘Negative data ignored’ warning.
Leah Shein
Leah Shein el 2 de Abr. de 2019
They're not zero, but they're still less than 10E-6 for the range I'm trying to show, and the values are supposed to range between around 200 and 700.
Star Strider
Star Strider el 3 de Abr. de 2019
You apparently miscoded something.
Unless I know what you’re coding, and can compare it to the code you posted, there’s nothing more I can do.

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Productos

Versión

R2018b

Etiquetas

Preguntada:

el 2 de Abr. de 2019

Comentada:

el 3 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by