Array reverting to 0 when called
Mostra commenti meno recenti
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);
Risposte (1)
Star Strider
il 2 Apr 2019
0 voti
Providing that none of your ‘xa’ values are negative or zero, use semilogy instead of plot.
4 Commenti
Leah Shein
il 2 Apr 2019
Star Strider
il 2 Apr 2019
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
il 2 Apr 2019
Star Strider
il 3 Apr 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.
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!