Clear Filters
Clear Filters

위치 2의 인덱스가 배열 경계를 초과합니다. 어떻게 해결하나요?

44 views (last 30 days)
Joye
Joye on 20 Jun 2024
Moved: Angelo Yeo on 28 Jun 2024 at 1:54
% Get info of recording dates
RecDates = readtextfile('Rec_dates.txt');
line1 = deblank(RecDates(1,:));
SurgeryDate = line1(9:end)
%SurgeryDate = input('Type the surgery date (e.g. 20220311)','s');
SurgeryDate2 = [SurgeryDate,'-000000-000'];
SurgeryDate3 = datenum(SurgeryDate2,'yyyymmdd-HHMMSS-FFF');
a=size(RecDates);
nRec = a(1)-1;
for n=1:nRec
line = deblank(RecDates(n+1,:));
Rec(n) = line(end);
end
% Get average amplitude and entropy envelopes of the 10+ model songs
Models = ls('ModelSongs4xcorr/*.wav');
clear Ampl Entr
for n=1:length(Models(:,1))
SoundFile = ['ModelSongs4xcorr/',deblank(Models(n,:))];
[Sound, Fs]=audioread(SoundFile);
if length(Sound(1,:))>1
Sound = Sound(:,1);
end
[SAPFeatures] = GetSAPFeatures(Sound,Fs);
Ampl{n} = SAPFeatures.Amplitude;
Entr{n} = SAPFeatures.Entropy;
end
위치 2의 인덱스가 배열 경계를 초과합니다.
오류 발생: SingRate_SongSort2_NHpC (line 22)
for n=1:length(Models(:,1))

Accepted Answer

Angelo Yeo
Angelo Yeo on 22 Jun 2024 at 23:47
올려주신 스크립트를 보았을 때,
Models = ls('ModelSongs4xcorr/*.wav');
라는 명령어를 통해 "ModelSongs4xcorr" 폴더 안의 wav 파일의 정보를 받아오려고 하는 것으로 보입니다. 그러나,
for n=1:length(Models(:,1))
이라는 스크립트에서 Models에 접근할 때 이 Models가 빈 벡터가 되면 말씀하신 "위치 2의 인덱스가 배열 경계를 초과합니다." 라는 에러가 발생할 수 있습니다. 예를 들면 아래와 같은 상황이 되겠습니다.
Models = [];
Models(:,1)
Index in position 2 exceeds array bounds.
  1 Comment
Joye
Joye on 28 Jun 2024 at 0:54
Moved: Angelo Yeo on 28 Jun 2024 at 1:54
감사합니다!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!