Subtraction inside a cell array

1 回表示 (過去 30 日間)
Tim Johansson
Tim Johansson 2020 年 10 月 19 日
編集済み: Walter Roberson 2022 年 10 月 25 日
Hello,
My data consists of several long EEG signals, and i would like to split these signal up into even smaller epochs.
My problem is that matlab is angry with me for trying to subtract inside a cell array.
I've tried the following code:
for b=1:20
for m = 1:20
rawData.sub1.run.epochs.run{b}.movement{m} = cz{b}(:,locs(m)-2*fs:locs(m)+2*fs);
end
end
As well as the same with cellfun
rawData.sub1.run.epochs.run{b}.movement{m} = cellfun(locs(m)-2*fs:locs(m)+2*fs,cz{b});
However, both methods give the error message
"Undefined function 'minus' for input arguments of type 'cell'."
Does anyone have any suggestions?
Thanks in advance.

回答 (1 件)

Stephen23
Stephen23 2020 年 10 月 19 日
編集済み: Stephen23 2020 年 10 月 19 日
You will have to get the numeric data out of the cell array before performing any numeric operations on it.
Although you did not actually given enough information in your question (or upload the relevant data) I am guessing that locs is a cell array containing numeric arrays, in which case you need to use curly braces to access its contents:
locs{m}
The difference is very simple:
  • {} curly braces refer to the cell contents.
  • () parentheses refer to the cells themselves.
  2 件のコメント
Tim Johansson
Tim Johansson 2020 年 10 月 19 日
編集済み: Walter Roberson 2022 年 10 月 25 日
I can see that the informations was a bit insufficient.
Locs is a 1x20 cell array in which a 1x20 array is placed in each.
as i write this i realise i might have mucked up.
i need to call the 20 values one at a time inside locs(1,1) and then move on to the next.
However, it seems that your tip with the braces solved the problem i asked about, as i am now getting a new error "First input must be a function handle."
Thanks for the help!
Stephen23
Stephen23 2020 年 10 月 19 日
@Tim Johansson: if my answer resolved your original question then please accept it.
'i am now getting a new error "First input must be a function handle." '
If you post the entire error message (this means all of the red text) then we could help you with that too.

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

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by