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

조회 수: 1 (최근 30일)
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

답변 (1개)

DGM
DGM 2021년 12월 3일
편집: DGM 2021년 12월 3일
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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by