Clear Filters
Clear Filters

Trying to use for loop for 2D cell array of {1X4}(1X11}

3 views (last 30 days)
for tr=2:ntr
Deman_EMG{tr}=cellfun(@minus,RawEMG{1,4}{tr},cellfun(@mean,RawEMG{1,4}{tr}));
end
Errorr: Error using cellfun
Input #3 expected to be a cell array, was double instead.

Answers (1)

Walter Roberson
Walter Roberson on 8 Dec 2022
cellfun() requires a function handle for the first parameter (with some obscure exceptions.)
cellfun() requires a cell array for its second parameter.
cellfun() can have trailing name, value pairs, such as 'UniformOutput', 0
Between the second parameter and the start of name/value pairs, there can be any number of additional cell arrays.
cellfun(@minus,RawEMG{1,4}{tr},cellfun(@mean,RawEMG{1,4}{tr}))
The parameters of a function are evaluated before the function is called. It is not immediately obvious what the datatype of RawEMG{1,4}{tr} is, but for the moment we can examine the call under the hypothesis that RawEMG{1,4}{tr} is a cell array.
The third parameter, cellfun(@mean,RawEMG{1,4}{tr}) must be evaluated in order to determine what value to pass as the third parameter to the outputer cellfun() call.
Again we do not know what datatype RawEMG{1,4}{tr} is but a second again we supposed it might be a cellfun, so let us continue with that idea. So suppose cellfun(@mean) is being called on a cell array. mean() applies to numeric values and returns a numeric value, and 'uniformoutput' was not specified, so that inner cellfun() is going to return a numeric array.
So now we have the outer cellfun() call with the parameters being a function handle, a (hypothetical) cell array... and a numeric array. But that is not permitted: all arrays passed must be cell arrays.
My guess is that what you want is
cellfun(@(C) C - mean(C), RawEMG{1,4}{tr}, 'uniform', 0)
  5 Comments
Walter Roberson
Walter Roberson on 9 Dec 2022
We are going to need example data with the exact same structure as your existing data to test with, as it sounds as if your actual data does not match the structure of data you described.
Kiran Isapure
Kiran Isapure on 9 Dec 2022
I have a nested cell array pos{1X4} >> {6830X1}{6824X1}{6834X1}{6826X1}{6842X1}{6840X1}{6836X1}{6844X1}{6837X1}{6833X1}.
Thanks

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!