how can i create a loop or function
Show older comments
I have an Excel sheet with many columns and rows.
Say column “y” has serval “groups” of the same numbers but the groups are any length, I want to find the length of each group of the same numbers then use that information to sum the value of a vector in column “k” The following code works, for the 1st three groups but there are 20+ groups in the column and I need to find a more efficient way to get the answer
[numbers, strings, raw] = xlsread('BCT2.csv');
colk= numbers(:,11);
coly =numbers(:,25);
cf=coly;
EI=colk;
z=cf-cf(1); %%subtracts the first value from vector cf
idx = find(z<=0);
x=length(idx);
y=1:x;
A=sum(EI(y));
v=x+1;% the new starting point
z=cf-cf(v);
idx = find(z<=0); % indices
x1=length(idx);
d=x1-x;
ya=1:d;
B = sum(EI(ya))-A;
v2=x1+1;
z=cf-cf(v2);
idx = find(z<=0); % indices
x2=length(idx);
d1=x2-x1;
ya=1:d1;
C = sum(EI(ya))-B;
Accepted Answer
More Answers (0)
Categories
Find more on Entering Commands in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!