Filter löschen
Filter löschen

How to sum according to specific ranges within same table?

4 Ansichten (letzte 30 Tage)
Harr
Harr am 30 Mär. 2021
Kommentiert: Harr am 1 Apr. 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?

Akzeptierte Antwort

Pavan Guntha
Pavan Guntha am 1 Apr. 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!
  1 Kommentar
Harr
Harr am 1 Apr. 2021
Dear Pavan,
Thank you very mcuh for your reply and the link! Probelm solved ^_^

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots 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!

Translated by