How to get mean of all variables in a table?
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kazi Alam
am 9 Apr. 2021
Bearbeitet: Kazi Alam
am 9 Apr. 2021
Hello, A table ('kub') that I am trying to analyse has a dimension of 1882x33. Its a mixed table with double and strings values. The 1st and 2nd variable is contains strings. Therefore, I used the following line of code to get the mean of all Variables except 1st and 2nd.
func = @mean;
B = varfun(func,kub{:,3:end});
However, I am getting the following error.
Check for missing argument or incorrect argument data type in call to function 'varfun'.+
Can anyone help me?
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 9 Apr. 2021
The varfun function requires one of its inputs to be a table or timetable array (or a tall table or timetable.)
which -all varfun
In your call the first input is a function handle. When you index into a table or timetable array using curly braces what you receive is not itself a table or timetable.
T = array2table(magic(4))
smallerTable = T(2:3, 2:4) % table array
doublePiece = T{2:3, 2:4} % double array
If you want to compute the mean of all the elements of the doublePiece variable don't use varfun.
M1 = mean(doublePiece, "all")
M2 = mean(doublePiece, 1)
M3 = mean(doublePiece, 2)
But if you want to operate on just the numeric variables in your table, you can use a function handle to select as the input variables only those that are numeric.
T.stringvar = ["a"; "b"; "c"; "d"]
varfun(@mean, T, 'InputVariables', @isnumeric)
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!