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);
回答(1 个)
Star Strider
2019-4-2
0 个投票
Providing that none of your ‘xa’ values are negative or zero, use semilogy instead of plot.
4 个评论
Leah Shein
2019-4-2
Star Strider
2019-4-2
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
2019-4-2
Star Strider
2019-4-3
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!