Calculate a return (base index)
Show older comments
I would like to calculate the column Base Index , for each particular ID is id(i)/id(base)*100, where id(base) is the first item FOR EACH id
ID Value Base Index
1 10 100
1 15 150 (e.g.15/10*100)
1 4 40
2 3 100
2 20 667
2 8 267
2 11 367
3 25 100
with this code I only get right answers for first id...how can I deal with the last one?
bvalue(1)=100;
for i=2:length(id)-1
if id(i)~=id(i-1) & id(i)==id(i+1)
bvalue(i)=100;
else
bvalue(i)=value(i)/value(id(i))*100;
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!