Index in position 1 exceeds array bounds (must not exceed 1) -- cannot fix behavior script

1 回表示 (過去 30 日間)
Hello!
I need help with my behavior script -- I am trying to plot a .mat file that has the dimensions of ans: [2×8297 double]. When I run it through a behavior script I am getting the error Index in position 1 exceeds array bounds (must not exceed 1).
I understand that the .mat file and its dimensions are the problem -- but how do I fix it?
Any help would be much appreciated, I have tried converting it to a txt file but haven't had any luck!
subject='racsleep04'
run='run01'
clicks=load(['racsleep04_a_run01_clicks.mat'])
%%
starttime = clicks(2,1); %HAVING ERROR ON THIS LINE
bp = clicks(2, find((clicks(1,:)~=22)&(clicks(1,:)~=0)))- starttime;
%% figure
figure(); subplot(2,1,1); plot(bp, ones(length(bp),1), '*'); title(['Button Press Times ', subject, ' ', run])
xlabel('Time');
subplot(2,1,2); plot(bp(2:end), diff(bp), '*'); title(['Button Press Intervals ', subject,' ', run]); xlabel('Time'); ylabel('Time since last click')

採用された回答

Walter Roberson
Walter Roberson 2020 年 11 月 27 日
When you load() and assign the output to a variable, the result is a struct with one field for each variable loaded.
clickstr = load(['racsleep04_a_run01_clicks.mat']);
clicks = clickstr.clicks;
  2 件のコメント
nines
nines 2020 年 11 月 27 日
thank you!
The value of clicks is 2*8000, and has a 1*1 structure, and so it is still not working -- do you have any ideas?
Walter Roberson
Walter Roberson 2020 年 11 月 27 日
In the above code, clickstr would be a struct with a field named for each variable stored in the file. Based on context it looks like you were expecting the file to have a variable named clicks, but if the variable name in the file is something else, then you need to use that on the line
clicks = clickstr.FileVariableNameGoesHere;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMRI についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by