How to sum according to specific ranges within same table?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Harr
el 30 de Mzo. de 2021
Comentada: Harr
el 1 de Abr. de 2021
Hello!
Available data: Please see the attached table.
Required: As shown in the same Excel file i would like to calculate the summ of test results for each person and based on four different intervals (1-10), (10-20), (20-30) and (30-40). then return a plot also for each person.
Any suggestions?
0 comentarios
Respuesta aceptada
Pavan Guntha
el 1 de Abr. de 2021
Hi Hedi,
You could load the excel file as a table. You could refer to this documentation page link for more details. The following code illustrates the further steps to calculate sum based on a condition:
c = categories(TestConditionalSum.AvailableData);
resCat = zeros(length(c),4);
for i = 1:length(c)
t = TestConditionalSum(TestConditionalSum.AvailableData == c{i},:);
for j = 1:size(t,1)
if(t(j,:).From >= 30)
resCat(i,4) = resCat(i,4) + t(j,:).Res; % Res is the name of T-Results column in the table
elseif(t(j,:).From >= 20)
resCat(i,3) = resCat(i,3) + t(j,:).Res;
elseif(t(j,:).From >= 10)
resCat(i,2) = resCat(i,2) + t(j,:).Res;
elseif(t(j,:).From >= 1)
resCat(i,1) = resCat(i,1) + t(j,:).Res;
end
end
end
b = barh(resCat(4,end:-1:1)); % Example plot for datapoint 'Maya'
ylabel('Maya')
yticklabels({'4','3','2','1'})
The resCat matrix contains the required sum for the 4 respective intervals for each of the available datapoints. You could refer to the documentation of barh function for more details on plotting. The plot for the above code is as follows:
Hope this helps!
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Preprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!