필터 지우기
필터 지우기

I need help with the error :Subscript indices must either be real positive integers or logicals.

조회 수: 3 (최근 30일)
load bach_fugue
bpm = 120;
bps = bpm/60;
spb = 1/bps;
spp = spb/4;
fs = 11025;
samples_per_pulse = 1/fs*spp;
xx0 = zeros(1, (sum(theVoices(1,1).durations)*spp*fs)+length(theVoices(1,1).noteNumbers));
n1 = spp*theVoices(1,1).startPulses;
for kk = 1:length(theVoices(1,1).noteNumbers);
n1 = spp*theVoices(1,1).startPulses;
keynum = theVoices(1,1).noteNumbers(kk);
dur= theVoices(1,1).durations(kk)*spp;
tone = key2note(1,keynum,dur);
n2 = n1 + length(tone) - spp*theVoices(1,1).startPulses;
xx0(n1:n2) = xx0(n1:n2) + tone;
n1 = n2 + spp*theVoices(1,1).startPulses;
end
This code loads a file called theVoices which has various values in each of the subsets, (startPulses,noteNumbers,and durations). Basically theres a problem with xx0(n1:n2) = xx0(n1:n2) + tone; not being an integer or logical from what i can tell, but I dont think I understand why?

답변 (2개)

nanren888
nanren888 2013년 3월 7일
Sorry a little too hard to read & simulate your file to put the time in just at the moment. . I'd start by putting these lines in ahead of the line giving you the problem
n1
n2
At least then you will know what values are causing you the problem.
Optionally also watch
length(tone)
theVoices(1,1).startPulses?
you could try a conditional breakpoint (right-click) the "-" at the start of the line & tell it (n1<1)

Walter Roberson
Walter Roberson 2013년 3월 7일
Your spp is 1/8. You then have n1 = spp * theVoices(1,1).startPulses which will only be an integer if theVoices(1,1).startPulses is exactly divisible by 8.
If you need to be able to have the startPulses not exactly match spp to become an integer, then you need to use a fractional delay filter instead of just indexing into an array. fractional delay mathematics is a bit ugly.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by