Function 'subsindex' is not defined for values of class 'cell'.
16 views (last 30 days)
Show older comments
Katarzyna Wieciorek
on 20 Mar 2015
Commented: Katarzyna Wieciorek
on 29 Apr 2015
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
0 Comments
Accepted Answer
Sean de Wolski
on 20 Mar 2015
Edited: Sean de Wolski
on 20 Mar 2015
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)
5 Comments
Sean de Wolski
on 22 Apr 2015
The commas aren't the problem
trials= [1 2 3]
for i = 1 : length(trials)
means(i) = mean(alldata(trials(i),:));
end
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!