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
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
Leah Shein 2019년 4월 2일
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 2019년 4월 2일
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 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에 대해 자세히 알아보기

제품

릴리스

R2018b

태그

질문:

2019년 4월 2일

댓글:

2019년 4월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by