Error while using cellfun with a function

I am using cellfun to apply a function on train and test variables for feature extraction. The function works absolutely fine when used without cellfun but with cellfun it gives an error. The code which I'm running:
RRTrain1 = cellfun(@(x)[rrvec] == RRfeatures(x),XTrain,'UniformOutput',false);
And this is the error which is appearing,
Unrecognized function or variable 'rrvec'.
Error in @(x)[rrvec]==RRfeatures(x)
However, rrvec is already declared within RRfeatures function. Can anyone please suggest how to solve this issue?

 Respuesta aceptada

Star Strider
Star Strider el 13 de Mayo de 2021
Try this instead —
RRTrain1 = cellfun(@(x)RRfeatures(x),XTrain,'UniformOutput',false);
I have no idea if that will do what you want.
More importantly, if the function works fine on its own, is there a specific reason for using cellfun?

4 comentarios

Arkaniva Sarkar
Arkaniva Sarkar el 14 de Mayo de 2021
The RRfeatures function generates a 1xn array as output whose value I'm pulling inside rrvec. That's why I'm using rrvec here.
I'm using cellfun as I'm working with around 5000 signals stored in a cell array and I think cellfun will help me apply the function to each signal inside the cell array.
Star Strider
Star Strider el 14 de Mayo de 2021
First, you did not say if the change I proposed did what you wanted.
Second,.using a loop with the original function would likely be easier and more efficient, since you already know that the function would work in that context.
Arkaniva Sarkar
Arkaniva Sarkar el 14 de Mayo de 2021
I solved the issue. It did not work that way. I had to use a counter instead of a loop. That served my purpose. Thank you for your help.
Star Strider
Star Strider el 14 de Mayo de 2021
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 13 de Mayo de 2021

Comentada:

el 14 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by