excel averageif function in matlab
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kuang-Yu WANG
el 29 de Jun. de 2018
Respondida: Steven Lord
el 29 de Jun. de 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 comentarios
Respuesta aceptada
Star Strider
el 29 de Jun. de 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 comentarios
Más respuestas (1)
Steven Lord
el 29 de Jun. de 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 comentarios
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!