Error: Index in position 1 exceeds array bounds.
Show older comments
I'm trying to import an xlsx file into MATLAB and make a simple graph of heart rate vs time. The time vector is from row 607 till 1947, and column 6 and the heart rate vector is from row 607 till 1947 and column 7. I get an error at the line HR=numData(607:1947,7); where it says Index in position 1 exceeds array bounds. Can anyone please help me in understanding where this error is coming from and how to fix it?
The code is given below:
clc
clear
close all
numData=xlsread('Pluto_5.30.19_Propofol_vitals_004.xlsx','Sheet2','F607:G1947')
dbstop if error
HR=numData(607:1947,7);
Time=numData(607:1947,6);
graph1=plot(HR,Time)
I'm attaching the Excel sheet below for reference.
Accepted Answer
More Answers (1)
You've told xlsread to import from row 607 to 1947, therefore, you'll get a (1947-607+1 = 1341) x 2 array, where row 1 corresponds to the original 607th row, row 2 the original 608th, ..., and row 1341 to the original 1947th row. Column 1 of the array in matlab is the original column 6, and column 2 is the original column 7.
You don't get a 1947x6 array where only rows 607 to 1947 and column 6 and 7 are filled.
So, simply:
numData=xlsread('Pluto_5.30.19_Propofol_vitals_004.xlsx','Sheet2','F607:G1947');
hline = plot(numData(:, 1), numData(:, 2))
and you're done
1 Comment
Zuha Yousuf
on 6 Aug 2019
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!