MATLAB: Function ‘subsindex’ is not defined for values of class ‘cell’.

cellindexingstruct

Hi,
I understand what error says but I don't know how to improve my function. I am not sure what exactly is seen as cell and how to achieve my goal. I loaded file to be read.
*Error using subsindex Function 'subsindex' is not defined for values of class 'cell'.
Error in EEGmeans (line 36) means(i) = mean(alldata(n,:));*
function [ means ] = EEGmeans( )
%EEGmeans loads the .mat file with EEG signal and calculates means for
%electrode and trials determined by user
%loading .mat file
load('eeg_data.mat');
%user determines number of elecrode and trials
for h=1:64
disp([num2str(h), ' - ', data_org.label{h}])
end
eprompt = 'Type number of electrode. You can see displayed numbers and labels in your command window.';
tprompt = 'Type numbers of trials (1-61) in form of a vector [t1, t2, t3, ...].';
edlg_title = 'Electrode';
tdlg_title = 'Trials';
num_lines = 1;
defe = {'1'};
deft = {'[1, 2, 3]'};
electrode = str2double((inputdlg(eprompt,edlg_title,num_lines,defe)));
trials = (inputdlg(tprompt,tdlg_title,num_lines,deft));
alldata = zeros(61,160);
%getting data for trials for selected electrode
for g = 1 : 61
alldata(g,:)=data_org.trial{g}(electrode,:);
end
%calculating means
means = zeros(1, length(trials));
for i = 1 : length(trials)
n = trials(i);
means(i) = mean(alldata(n,:));
end
%displaying results
msgbox('Operation Completed. Arithmetic means for given electrode and trials are as follows: ', 'Success','custom', means);
end

Best Answer

trials is a cell array or a container, when you create n, n is a cell and you cannot index with a cell:
c = {1}
c =
[1]
>> x = magic(3)
x =
8 1 6
3 5 7
4 9 2
>> x(c,2)
Error using subsindex
Function 'subsindex' is not defined for values of class 'cell'.
You likely need to use {} to extract the n from trials:
n = trials{i}
This extracts the contents of the cell into n rather than the cell itself. For my simple example:
x(c{1},2)