splitapply with own created function
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Senne Van Minnebruggen
le 1 Avr 2020
Commenté : Senne Van Minnebruggen
le 2 Avr 2020
I have 'nr' tables containing the following: date/time/Qdot/temperature
i would like to apply a function to this tables more specific i would like to apply a function on data grouped by day (date)
herefor i've tried to use the function splitapply where the function is of my own creating
for j=2:24
s = (j-1); %sizetimestep - 1stap
for i=1:nr
[G,days] = findgroups(DayT{i}.date);
max_Qdot = splitapply(@maxperinterval,DayT{i}.Qdot,s,G);
Mean_T = splitapply(@mean,DayT{i}.Temperature,G);
Max_tabel{j,i}=table(days,max_Qdot,Mean_T,'VarbiableNames',rownames);
end
end
But when i tried to run this i get an error saying the following:
"The data variables must have the same number of rows as the vector of group numbers. The group number vector
has 5736 row(s), and data variable 2 has 1 row(s)."
My own function needs the input of variable s.
Is this even possible to use this function with splitapply?
0 commentaires
Réponse acceptée
Rik
le 1 Avr 2020
Modifié(e) : Rik
le 1 Avr 2020
You can probably get around this by wrapping your function in an anonymous function:
fun=@(input1)maxperinterval(input1,s);
max_Qdot = splitapply(fun,DayT{i}.Qdot,G);
Now the function splitapply is looking at only requires 1 input variable while your function will receive both. Note that you will need to generate fun every time you update s.
Plus de réponses (1)
Ameer Hamza
le 1 Avr 2020
As the error indicate. The error is related to the orientation of matrices. Change it like this
max_Qdot = splitapply(@maxperinterval,DayT{i}.Qdot,s.',G); % use transpose of s so that it become column matrix
0 commentaires
Voir également
Catégories
En savoir plus sur String Parsing 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!