Plot function suddenly not working (getting error: Index in position 1 is invalid. Array indices must be positive integers or logical values.) Even for MATLAB examples
4 次查看(过去 30 天)
显示 更早的评论
I have some simple plots
IMU = imuSensor('accel-gyro-mag')
numSamples = 1000;
acceleration = zeros(numSamples,3);
angularVelocity = zeros(numSamples,3);
[accelReading,gyroReading,magReading] = IMU(acceleration,angularVelocity);
t = (0:999);
subplot(3,1,1)
plot(t,accelReading(3))
legend('X-axis','Y-axis','Z-axis')
title('Accelerometer Readings')
ylabel('Acceleration (m/s^2)')
subplot(3,1,2)
plot(t,gyroReading)
legend('X-axis','Y-axis','Z-axis')
title('Gyroscope Readings')
ylabel('Angular Velocity (rad/s)')
subplot(3,1,3)
plot(t,magReading)
legend('X-axis','Y-axis','Z-axis')
title('Magnetometer Readings')
xlabel('Time (s)')
ylabel('Magnetic Field (uT)')
Literally a MATLAB example btw^^
But for this and other plot functions I keep getting "Index in position 1 is invalid. Array indices must be positive integers or logical values." For the line with the plot function
Obviously I've checked and the variables are all fine and normal. I've also entered
>> which -plot all
(and get)
'-plot' not found.
Any idea whats going on? :)
0 个评论
回答(2 个)
Steven Lord
2023-7-21
The correct command to check whether or not you've created a variable named plot is the following:
which -all plot
You had the - associated with plot not all. I suspect that you previously created a variable named plot that's taking precedence over the plot function included in MATLAB. Assign the contents of that variable to another variable (like myplot) if you need the data it contains then clear that variable.
0 个评论
Sarvesh Kale
2023-7-21
Could you please avoid using "IMU" as the name for the imuSensor object since "IMU" is a reserved name in MATLAB. Please try using a different name and see if that resolves the issue.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!