I'm getting this as error on 2nd line --> Index in position 2 exceeds array bounds (must not exceed 1).

1 view (last 30 days)
ecg_nsr = load('ecg_nsr.mat')
mat=ecg_nsr(:,3); % mat=ecg_nsr(:,1:15);
[r,c]=size(mat);
%r=1800;
wsize=50;
st=1:wsize:r;
en=wsize:wsize:r;
if(length(st)>length(en))
en=[en,r];
end
% if((st(end)-en(end))<c)
% st(end)=[];
% en(end)=[];
% end
result={};
F={};
Fmat={};
len=length(st);
reg=reg_mat;
parfor i=1:len
i
ori_mat=mat(st(i):en(i),:);
reg=reg_mat(st(i):en(i),:);
[FitArray,FitMat, offsprings]=permute_one(ori_mat,mat, reg);
F{i}=FitArray;
result{i}=offsprings;
Fmat{i}=FitMat;
end

Answers (1)

DGM
DGM on 3 Dec 2021
Edited: DGM on 3 Dec 2021
The functional syntax for load behaves differently than the command syntax. Say you have a matfile containing arrays X,Y, and Z. If using the command syntax as follows
load myfile.mat
The arrays X, Y, Z will just magically appear in the workspace. This is both attractive in its simplicity and incredibly problematic. Just as I can't look at the code and know what variables are (or aren't) going to show up, neither can MATLAB. This is discouraged practice; kudos for not doing it!
On the other hand, using the functional syntax like this
S = load('mymatfile.mat');
will load X,Y, and Z into a the scalar struct S. They could be accessed as S.X, S.Y, and S.Z.
So now we have this:
ecg_nsr = load('ecg_nsr.mat')
mat = ecg_nsr(:,3);
ecg_nsr is a scalar struct, so it doesn't have a third column to index into. If the contents of the matfile is a single array called "ecg_nsr", then you can use it in-place, or make a copy.
S = load('ecg_nsr.mat')
mat = S.ecg_nsr(:,3); % use in-place

Categories

Find more on Matrices and Arrays 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!