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

2 Ansichten (letzte 30 Tage)
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')

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 27 Nov. 2020
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 Kommentare
nines
nines am 27 Nov. 2020
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 am 27 Nov. 2020
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;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MRI finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by