How to do sum?

4 Ansichten (letzte 30 Tage)
vimal kumar chawda
vimal kumar chawda am 16 Jul. 2020
Beantwortet: Monisha Nalluru am 14 Aug. 2020
I have data of 1891*4. In first row I have degree from 0 to 60 which has repetation of degree and I want to add all the same degree values which are in column 3 and add for column 4too. How can I do it?
if you load the data we are getting shc_06 and shc_12. Please find the attachment of code but I dont know how to calculate of same number degree in column1 have to added in column 3 and 4 respectively. So i will get 60*1 as output because the in column one we are having range from 0 to 60.
load('aiub_shc.mat')
k=1;
j=1;
del_cl_06 = shc06(:,3);
del_sl_06 = shc06(:,4);
del_cl_12 = shc12(:,3);
del_sl_12 = shc12(:,4);
for i=1:1:size(shc06)
if all(shc06(j,1))
std_cl_06(j,k)= del_cl_06(i,k)^2+del_sl_06(i,k)^2;
std_cl_12(j,k)= del_cl_12(i,k)^2+del_sl_12(i,k)^2;
j=j+1;
else
i=i+1;
end
end

Antworten (1)

Monisha Nalluru
Monisha Nalluru am 14 Aug. 2020
From my understanding, you want to first group the data based on temperature and then add the values of values of 3rd and 4th column based on grouping.
In this case you may use findgroups in order to group the data and to perform operation on grouped data you can use splitapply
You may use below code as example
load('aiub_shc.mat')
G = findgroups(shc12(:,1));
col2sum=splitapply(@sum,shc12(:,2),G);
col3sum=splitapply(@sum,shc12(:,3),G);
col4sum=splitapply(@sum,shc12(:,4),G);
Hope this gives an idea!

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by