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 (최근 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에서 Formatting and Annotation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!