excel averageif function in matlab
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Kuang-Yu WANG
il 29 Giu 2018
Risposto: Steven Lord
il 29 Giu 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.
0 Commenti
Risposta accettata
Star Strider
il 29 Giu 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 Commenti
Più risposte (1)
Steven Lord
il 29 Giu 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)
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!