splitapply with own created function
11 ビュー (過去 30 日間)
古いコメントを表示
Senne Van Minnebruggen
2020 年 4 月 1 日
コメント済み: Senne Van Minnebruggen
2020 年 4 月 2 日
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 件のコメント
採用された回答
Rik
2020 年 4 月 1 日
編集済み: Rik
2020 年 4 月 1 日
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.
その他の回答 (1 件)
Ameer Hamza
2020 年 4 月 1 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!