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

5 views (last 30 days)
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? :)

Answers (2)

Steven Lord
Steven Lord on 21 Jul 2023
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.

Sarvesh Kale
Sarvesh Kale on 21 Jul 2023
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.

Categories

Find more on Formatting and Annotation in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!