How to use the parameters of other functions within the ‘cellfun’ function?

Hello guys, just a simple question. I don’t find the way how to use the parameters ‘movemedian’ , ‘lowess’ and so on .. belonging to the ‘smoothdata’ function inside the ‘cellfun’ , how can you do this? Thank you.
x=cellfun(@smoothdata,C1,('movemedian',100),'UniformOutput',false); %there is a mistake here calling the parameters for 'smoothdata'

 Réponse acceptée

Stephen23
Stephen23 le 29 Avr 2021
Modifié(e) : Stephen23 le 29 Avr 2021
f = @(a)smoothdata(a,'movemedian',100);
x = cellfun(f,C1,'UniformOutput',false);

9 commentaires

it worked like that, thank's a lot ;)
@Stephen Cobeldick what about for the 'findpeaks' function? ; having a structure like this:
[pks,locs,widths,proms] = findpeaks(r,y,'MinPeakHeight',20); widths; proms;
findpeaks(r,y,'Annotate','extents','WidthReference','halfprom');
the 'cellfun' funtion it wont work propertly.
Y = {1:7,1:7};
R = {50*rand(1,7),50*rand(1,7)};
F = @(r,y)findpeaks(r,y,'MinPeakHeight',20,'Annotate','extents','WidthReference','halfprom');
[pks,locs,widths,proms] = cellfun(F,R,Y,'uni',0)
pks = 1×2 cell array
{[30.0986]} {[44.1002]}
locs = 1×2 cell array
{[6]} {[3]}
widths = 1×2 cell array
{[0.9610]} {[2.6194]}
proms = 1×2 cell array
{[17.1221]} {[32.4057]}
Note that you can always just use a loop: CELLFUN is handy in some circumstances where it can compact an operation down to a neat line or so of code, but it is slower than a loop and not always simpler.
@Stephen Cobeldick ok, and how can I do loop for this case?
@Stephen Cobeldick I was triying to do a loop in this way..
FigH = figure;
for cv=1:numel(smt1)
ax1=subplot(4, 6, cv6, 'Parent', FigH);
[pks,locs,widths,proms] = findpeaks((smt1{1,cv}(:,end)),y,'MinPeakHeight',20); widths; proms;
findpeaks((smt1{1,cv}(:,end)),y,'Annotate','extents','WidthReference','halfprom');
text(locs+0.5,pks,num2str((1:numel(pks))'));
legend('Filtered Data','Peak','Prominence','Width','FontSize',5);
end
but it doesn't work.
"but it doesn't work."
I have no idea what you expect to occur, nor did you write what actually happens.
@Stephen Cobeldick it's the way how the loop was formulated for ths case, but there is Something wrong with the syntaxis, the idea is to do a loop for the variable smt showing its respective plots and as a result [pks,locs,widths,proms] as cell array.
If you want to keep pks, etc. to use after the loop then you will need to use indexing into some variable, e.g.:
N = numel(smt1);
pks = cell(1,N);
locs = cell(1,N);
widths = cell(1,N);
proms = cell(1,N);
for cv = 1:N
..
[pks{cv},locs{cv},widths{cv},proms{cv}] = findpeaks(..);
..
end
@Stephen Cobeldick thank's.. using your structure is the best and the fastest solution.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by