フィルターのクリア

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 Center および File ExchangeAxis Labels についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by