Problem with direct calculation on table with std and "omitnan"
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jean-Marie Sainthillier
am 17 Mai 2023
Beantwortet: Steven Lord
am 13 Aug. 2024
Since R2023a, it is possible to perform calculations directly on tables (and timetables) without extracting their data by indexing.
I want use std directly on a numeric table where I can have nan.
For example :
load patients
T = table(Age,Height,Weight,Systolic,Diastolic)
mean(T,"omitnan")
It's fine.
But why there is a problem with std(T,"omitnan") ?
% Applying the function 'std' to the variable 'Age' generated an error.
I can use std(T{:,:},"omitnan") or std(T.Variables,"omitnan") but I lost the possibility to work directly with my table.
Did I miss something ?
Do you have any suggestion ?
Thank you in advance.
SAINTHILLIER Jean Marie
0 Kommentare
Akzeptierte Antwort
Star Strider
am 17 Mai 2023
Example —
load patients
T = table(Age,Height,Weight,Systolic,Diastolic)
S = varfun(@(x)std(x,'omitnan'),T)
.
3 Kommentare
Keith Goatman
am 13 Aug. 2024
I too was caught out by the inconsistent behaviour of mean and std on tables in 2024a. The answer above works around it but it doesn't explain why they should behave differently.
Weitere Antworten (1)
Steven Lord
am 13 Aug. 2024
This looks like a bug to me. It seems that std for table arrays assumes that if you're passing the missingflag input that you've also specified the normalization option or weights. But specifying just the data and the missingflag input is a supported syntax for a double array input and so probably should be supported for a table array input.
A workaround is to specify the default normalization option (0) in the std call as the second input.
load patients
T = table(Age,Height,Weight,Systolic,Diastolic);
mean(T,"omitnan")
std(T, 0, "omitnan")
% check
std(T.Age, "omitnan")
I'll report this to the development staff.
0 Kommentare
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!