Error: Index in position 1 exceeds array bounds.

4 ビュー (過去 30 日間)
Zuha Yousuf
Zuha Yousuf 2019 年 8 月 6 日
コメント済み: Star Strider 2019 年 8 月 6 日
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.

採用された回答

Star Strider
Star Strider 2019 年 8 月 6 日
Try this:
[~,NumDataS]=xlsread('Pluto_5.30.19_Propofol_vitals_004.xlsx','Sheet2','F607:G1947'); % Physiological Data
[~,TmatrixS] = xlsread('Pluto_5.30.19_Propofol_vitals_004.xlsx','Sheet2','A607:F1947'); % Time Data
HR = cellfun(@str2double, NumDataS(:,2)); % Retrieve From Cell Array Of Strings
Timemtx = cellfun(@str2double, TmatrixS); % Retrieve From Cell Array Of Strings
Time = datenum(Timemtx); % Date Numbers
DTime = datetime(Timemtx); % ‘datetime’ Array
figure
graph1=plot(Time, HR);
datetick('x', 'HH:MM:SS.FFF', 'keepticks')
figure
graph2=plot(DTime, HR);
It makes several improvements, and actually appears to plot your data correctly w.r.t. time.
  2 件のコメント
Zuha Yousuf
Zuha Yousuf 2019 年 8 月 6 日
Thank you so much! That worked.
Star Strider
Star Strider 2019 年 8 月 6 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Guillaume
Guillaume 2019 年 8 月 6 日
編集済み: Guillaume 2019 年 8 月 6 日
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 件のコメント
Zuha Yousuf
Zuha Yousuf 2019 年 8 月 6 日
Hi! When I do that, I get the following error:
Index in position 2 exceeds array bounds.
Error in Graphstuff (line 8)
hline = plot(numData(:, 1), numData(:, 2))

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by