Index in position 2 exceeds array?

My code starts at connector on:
connector on MDTP1
m = mobiledev;
m.AngularVelocitySensorEnabled = 1;
m.AccelerationSensorEnabled = 1;
m.Logging = 1;
for K = 1 : 5; pause(1); end
m.Logging = 0;
[av, tav] = angvellog(m);
[o, to] = orientlog(m);
yAngVel = av(:,2);
roll = o(:, 3);
plot(tav, yAngVel, to, roll);
legend('Y Angular Velocity', 'Roll');
xlabel('Relative time (s)');
tInit = datetime(m.InitialTimestamp, 'InputFormat', 'dd-MM-yyyy HH:mm:ss.SSS');
tAngVel = tInit + seconds(tav);
tOrient = tInit + seconds(to);
yAngVelDeg = yAngVel * 180/pi;
plot(tAngVel, yAngVelDeg, tOrient, roll);
legend('Y Angular Velocity', 'Roll');
xlabel('Absolute time (s)');
m.AngularVelocitySensorEnabled = 0;
clear m;
So I made this program, and it runs on my Android phone. It's supposed to collect data from the sensors available in the mobile MATLAB app and graph it. I ran the program once, and it worked. But now this error pops up when I run the code:
index in position 2 exceeds array bounds.
What does this mean and how would I fix it?

댓글 수: 5

What line of code is it talking about? If it's one of these:
yAngVel = av(:,2);
roll = o(:, 3);
then either av is not really a 2-D array, or o does not have at least 3 columns. What are the sizes of those variables?
Please include the entire error message, not just a snippet from it.
Ryan Leonard
Ryan Leonard 2018년 3월 16일
I did, that's all that's there besides it telling me that an instance of mobiledev is already running but im not sure how to stop the other instance of mobiledev
dpb
dpb 2018년 3월 16일
편집: dpb 2018년 3월 17일
I don't know how mobile Matlab handles workspace but I presume this runs as a script in one. As such, the first time it runs none of the variables are extant and Matlab will create them dynamically. The next time, however, there likely are pre-existing variables left over.
I observe the last line is
clear m
that closes and deletes the device object but it says nothing about av, tav, o, to so I'm guessing they're still around.
Try
clear all
first and see if it then runs. If so, add them to the clear statement.
NB: this is purely speculation; I've no experience from which to have any idea how it actually works...
A lot of objects ( tcpip, udp, timer) don't die with clear, just the variable from the workspace. This might be true of mobiledev objects. Try:
delete('m');
clear('m');
On top of what dpb recommends.
dpb
dpb 2018년 3월 18일
Good point Greg, I think there should be automagic destructors called so one isn't left with zombies...

댓글을 달려면 로그인하십시오.

답변 (1개)

Greg
Greg 2018년 3월 18일
편집: Greg 2018년 3월 18일

0 개 추천

Adjust your code to:
connector off
clear m

카테고리

도움말 센터File Exchange에서 Sensor Data Collection에 대해 자세히 알아보기

태그

질문:

2018년 3월 16일

댓글:

dpb
2018년 3월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by