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

1 view (last 30 days)
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 Comments
Dhanashree Mohite
Dhanashree Mohite on 8 Apr 2019
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 on 8 Apr 2019
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!

Sign in to comment.

Answers (1)

KSSV
KSSV on 8 Apr 2019
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 Comment
Luca Merolla
Luca Merolla on 8 Apr 2019
Hi! I tried your suggestion but it doesn't work. Anyway, I seem to have solve it somehow, thank you!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!