Effacer les filtres
Effacer les filtres

excel averageif function in matlab

8 vues (au cours des 30 derniers jours)
Kuang-Yu WANG
Kuang-Yu WANG le 29 Juin 2018
for cata = 1:281
mydata = mean(cellfun(@(x) x(cata,2), thecells));
data2 = cell2mat(num2cell(mydata));
plot(cata,data2)
end
mydata is 5000*2 double look like
time data
1 225.42968
1 453.4097824
1 254.1819706
2 164.3800456
2 411.2133781
2 266.0093299
2 399.3169552
3 155.2650000
4 322.7854587
4 366.5487525
i try many methods but cannot create a loop same as averageif function in excel. my prof tell me to put nan for numbers to create same size for each time. But I am wondering another ways of the averageif function in excel.

Réponse acceptée

Star Strider
Star Strider le 29 Juin 2018
I am not certain what structure your original data are.
Try this:
C = {1 225.42968
1 453.4097824
1 254.1819706
2 164.3800456
2 411.2133781
2 266.0093299
2 399.3169552
3 155.2650000
4 322.7854587
4 366.5487525};
M = cell2mat(C);
Out = accumarray(M(:,1), M(:,2), [], @mean);
  2 commentaires
Kuang-Yu WANG
Kuang-Yu WANG le 29 Juin 2018
thanks very much!!
Star Strider
Star Strider le 29 Juin 2018
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Steven Lord
Steven Lord le 29 Juin 2018
If you're using release R2018a and your data is stored as a table, use groupsummary.
time = [1; 1; 1; 2; 2; 2; 2; 3; 4; 4];
data = [225.42968;
453.4097824;
254.1819706;
164.3800456;
411.2133781;
266.0093299;
399.3169552;
155.2650000;
322.7854587;
366.5487525];
T = table(time, data)
groupsummary(T, 'time', 'mean')
Or you could use splitapply (since your times are already group numbers; if they weren't a vector of positive integer values you would need to use findgroups first.)
meantime = splitapply(@mean, data, time)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by