필터 지우기
필터 지우기

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

조회 수: 3 (최근 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? :)

답변 (2개)

Steven Lord
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.

Sarvesh Kale
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.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by