Why do I receive "Index in position 2 exceeds array bounds (must not exceed 1)" error?
Show older comments
% Setup the Import Options and import the data
opts = spreadsheetImportOptions("NumVariables", 3);
% Specify sheet and range
opts.Sheet = "Sheet1";
opts.DataRange = "A2:C170641";
% Specify column names and types
opts.VariableNames = ["Instrument", "TimeofDayhrs", "LaeqdBA"];
opts.VariableTypes = ["categorical", "double", "double"];
% Specify variable properties
opts = setvaropts(opts, "Instrument", "EmptyFieldRule", "auto");
% Import the data
AcftNoiseData = readtable("/Applications/StirlingMATLAB/AcftNoiseData.xlsx", opts, "UseExcel", false);
% Clear temporary variables
clear opts
%Initialize Variables
instrument=AcftNoiseData.Instrument;
time=AcftNoiseData.TimeofDayhrs;
Laeq=AcftNoiseData.LaeqdBA;
%Plotting LAeq Noise Levels
x=time;
y=Laeq;
subplot(2,1,1)
plot(x(1,1:85320),y(1,1:85320));
grid
subplot(2,1,2)
plot(x(1,85321:170640),y(1,85321:170640));
grid
***Index in position 2 exceeds array bounds (must not exceed 1).
Error in AircraftNoiseData (line 39)
plot(x(1,1:85320),y(1,1:85320));
I am trying to divide my data into two plots, each containing the data for a resepctive instrument type, which changes from one to the other at index 85320. I thought I was able to do what I did with my subplot and plot codes, but clearly can't. IF anyone knows my issue I would love help. Apologies if this is a stupid question. Thank you!
2 Comments
DGM
on 13 Apr 2022
The error suggests that the second dimension of x or y is 1. So what are the sizes of x and y?
Stirling Ellis
on 13 Apr 2022
Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!