How to solve error "Index exceeds the number of array elements (1)."?

조회 수: 1 (최근 30일)
Luca Merolla
Luca Merolla 2019년 4월 5일
댓글: Luca Merolla 2019년 4월 8일
Hello everyone! I am trying to make a staircase threshold with auditory stimuli. My code is pretty simple: I have 5 sounds at frequencies immerse in noise, I randomise their presentation while decreasing or increasing the SNR depending on the response of the subject.
myPitches = [500, 1000, 1500, 2000, 2500];
condition_fs = [1 2 3 4 5];
howLong = .5;
presentedPitches = [];
for condition = 1:5 % five frequencies
for trial = 1:20 % presentation for each frequency
% Random presentation of sounds at different pitches
RandPitches = randperm(5,1);
pitch = myPitches(RandPitches(condition_fs));
presentedPitches(condition_fs, trial) = pitch; % save pitches
pause(1.5)
[beep] = MakeBeep(pitch, howLong, samplingRate);
end
end
This is part of my code. The error occurs at line 5 "Index exceeds the number of array elements (1)". I can't work out what it even means and I can't solve it.
Can someone help me please?
Thanks a lot guys!
  댓글 수: 2
Dhanashree Mohite
Dhanashree Mohite 2019년 4월 8일
As per my understanding, Line no. 5 should contain 'condition_fs' instead of 'condition'.
it should be:
for condition_fs = 1:5
Hope you have 'samplingRate' defined. Else it will give error as:
Undefined function or variable 'samplingRate'
Luca Merolla
Luca Merolla 2019년 4월 8일
Yes sorry, that was a little oversight that I corrected, and yes my samplingRate is defined. However, still the error occurs. I solved it this way:
pitch = myPitches(RandPitches);
and now seems to work fine.
Thank you for your help!

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2019년 4월 8일
myPitches = [500, 1000, 1500, 2000, 2500];
condition_fs = [1 2 3 4 5];
howLong = .5;
presentedPitches = [];
for condition = 1:5 % five frequencies
for trial = 1:20 % presentation for each frequency
% Random presentation of sounds at different pitches
RandPitches = randperm(5,1);
pitch = myPitches(condition_fs(RandPitches));
presentedPitches(condition_fs, trial) = pitch; % save pitches
pause(1.5)
[beep] = MakeBeep(pitch, howLong, samplingRate);
end
end
  댓글 수: 1
Luca Merolla
Luca Merolla 2019년 4월 8일
Hi! I tried your suggestion but it doesn't work. Anyway, I seem to have solve it somehow, thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by