Trying to use for loop for 2D cell array of {1X4}(1X11}
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
Walter Roberson
le 8 Déc 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 commentaires
Walter Roberson
le 9 Déc 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.
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!