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

1 次查看(过去 30 天)
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
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

类别

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