フィルターのクリア

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 Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by