フィルターのクリア

How to sum according to specific ranges within same table?

4 ビュー (過去 30 日間)
Harr
Harr 2021 年 3 月 30 日
コメント済み: Harr 2021 年 4 月 1 日
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?

採用された回答

Pavan Guntha
Pavan Guntha 2021 年 4 月 1 日
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 件のコメント
Harr
Harr 2021 年 4 月 1 日
Dear Pavan,
Thank you very mcuh for your reply and the link! Probelm solved ^_^

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by