Function 'subsindex' is not defined for values of class 'cell'.

5 ビュー (過去 30 日間)
Katarzyna Wieciorek
Katarzyna Wieciorek 2015 年 3 月 20 日
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

採用された回答

Sean de Wolski
Sean de Wolski 2015 年 3 月 20 日
編集済み: Sean de Wolski 2015 年 3 月 20 日
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 件のコメント
Sean de Wolski
Sean de Wolski 2015 年 4 月 22 日
The commas aren't the problem
trials= [1 2 3]
for i = 1 : length(trials)
means(i) = mean(alldata(trials(i),:));
end
Katarzyna Wieciorek
Katarzyna Wieciorek 2015 年 4 月 29 日
trials are supposed to be typed by user in dialog box and then they are cell (this is how inputdlg works), so for your solution:
Error using subsindex
Function 'subsindex' is not defined for values of class 'cell'.
Error in EEGmeans (line 35)
means(i) = mean(alldata(trials(i),:));
when I do trials{i}:
Index exceeds matrix dimensions.
Error in EEGmeans (line 35)
means(i) = mean(alldata(trials{i},:));

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by