Trying to remove zeroes from dataset to determine a proper min, max, mean and median
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Nathaniel Porter
am 15 Dez. 2021
Kommentiert: Image Analyst
am 15 Dez. 2021
%Tried using this method but completely gets rid of columns with zeroes
load generated_data.mat
colsWithZeros = any(X1==0)
X1_glc = X1(:, ~colsWithZeros)
mean = mean(X1)
median = median(X1)
max = max(X1)
min = min(X1)
0 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 15 Dez. 2021
You could replace the zeros with NaN, then use the 'omitnan' option in the mean, median, max and min functions.
load generated_data.mat
xX1 = X1;
xX1(xX1==0)=missing;
mean(xX1,"omitnan")
median(xX1,"omitnan")
max(xX1,[],"omitnan")
min(xX1,[],"omitnan")
By the way, you want to avoid naming your variables the same as MATLAB functions. That replaces the function with the variable, which will prevent you from using the function.
mean = mean(xX1);
% example of what happens when a varible replaces a MATLAB Function
mean2 = mean(X2;)
2 Kommentare
Image Analyst
am 15 Dez. 2021
Exactly what I was going to suggest. So Nathaniel, could you click the "Accept this answer" if you think it solved your question to award Chris reputation points?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices 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!