配列インデックスのエラーメッセージについて

8 views (last 30 days)
Kirari Wada
Kirari Wada on 30 Sep 2022
Commented: Kirari Wada on 30 Sep 2022
下記のようなプログラムで、エラーメッセージが出ます。どのように直せば良いですか。
if ~isnan(t_TRGe_V(1))==1
for t = 2:length(t_TRGe_V)-1
pFp1_V = [pFp1_V;Fp1_V(t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2))'];
pFp2_V = [pFp2_V;Fp2_V(t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2))'];
pFC3_V = [pFC3_V;FC3_V(t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2))'];
pFC4_V = [pFC4_V;FC4_V(t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2))'];
pO1_V = [pO1_V;O1_V(t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2))'];
pO2_V = [pO2_V;O2_V(t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2))'];
pP5_V = [pP5_V;P5_V(t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2))'];
pP6_V = [pP6_V;P6_V(t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2))'];
end
配列インデックスは正の整数または logical 値でなければなりません。
エラー: EEG_test (行 82)
pFp1_V = [pFp1_V;Fp1_V(t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2))'];

Accepted Answer

Kojiro Saito
Kojiro Saito on 30 Sep 2022
MATLABのエディターで該当行 (EEG_test.mの82行目)の行番号をマウスでクリックしてブレークポイントを設定してみてください。
下記の図では3行目をクリックした場合ですが、ブレークポイントが設定されると赤枠で表示されます。
【参考ドキュメント】ブレークポイントを設定する
そして再度スクリプトを実行してみて、ブレークポイントで一時停止した状態でコマンドウィンドウで
t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2)
を実行してみてください。
ここが正の整数になっていれば問題ないので、「再開」をクリックして次のfor文の繰り返しを実行します。
どこかのtの値で、t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2)がマイナスの値とか小数になっている可能性があります。
そしたらコマンドウィンドウで
t_TRGe_V(t)
analwin_eeg_V(1)
とか
analwin_eeg_V(2)
を実行して原因を特定できます。
  1 Comment
Kirari Wada
Kirari Wada on 30 Sep 2022
ご教授ありがとうございます。
教えていただいたコードを入力するとエラー箇所を見つけることができました。指摘していただいた通りtの値がマイナスになっていました。
t値の範囲を修正し、無事に実行することができました。
ありがとうございました。

Sign in to comment.

More Answers (1)

Hernia Baby
Hernia Baby on 30 Sep 2022
t_TRGe_V(t)+analwin_eeg_V(1):t_TRGe_V(t)+analwin_eeg_V(2)
上記が正の整数でないことが問題です。
Fp1_V の 0.001番目 と言われてエラーが起きてる感じです。
  1 Comment
Kirari Wada
Kirari Wada on 30 Sep 2022
ご教授ありがとうございます。
t値の範囲を変更し無事に実行できました。
ありがとうございました。

Sign in to comment.

Categories

Find more on 起動と終了 in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!