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')
0 个评论
采纳的回答
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 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!