Error: Undefined operator '-' for input arguments of type 'cell'.

2 次查看(过去 30 天)
Hello Matlab experts,
I am trying to subtract 6 secs off of the onset times that I have extracted from an excel file. I now have a series of vectors with the onset times (just a column of numbers) saved in .mat files. I am running into an Error: Undefined operator '-' for input arguments of type 'cell'. I just used the following code:
neutral_cue_onset_time_adjusted=neutral_cue_onset_time-6;
save ('neutral_cue_onset_time_adjusted.mat', 'neutral_cue_onset_time_adjusted');
The previous code I used to find and extract onset times was:
[num,txt,raw] = xlsread ('Placebo_MID_Reward_PLAEGO002_session1_Neutral.xlsx');
% Extract all cue-type onset times
cue_type=raw(:,7);
cue_block_onset=raw(:,9);
neutral_index=find(strcmp(cue_type(:),'neutral'));
neutral_cue_onset_time=cue_block_onset(neutral_index);
save ('neutral_cue_onset_time.mat', 'neutral_cue_onset_time');
I would appreciate any guidance!
Emily

回答(2 个)

Alexandra Harkai
Alexandra Harkai 2016-10-27
If you want to preserve the shape of your cell array neural_cue_onset_time, you can convert the cells to the underlying data type, subtract 6, then back to the proper shape of cell array:
neutral_cue_onset_time_adjusted = mat2cell(cell2mat(neutral_cue_onset_time)-6, [dim1, dim2])

Greg Heath
Greg Heath 2016-10-27
Cut and paste into the command line
a = 10, b=5
A = num2cell(a)
B = num2cell(b)
c = b-a
C = gsubtract(B,A)
C = B-A
Hope this helps.
Thank you for formally accepting my answer
Greg

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by