Percentage increase for table variables

I have a 6x18 table. All with numeric values. How can I compute the percentage increase for all variables ? I tried using rowfun with diff(x) ./x(1:end-1)*100 but I am getting too many input variables error

 Accepted Answer

Adam Danz
Adam Danz on 28 Aug 2020
Edited: Adam Danz on 28 Aug 2020
If I'm understanding the problem correctly, the result would be an 6x17 matrix "M" where
% P is the 6x18 input table converted to a matrix
M(i,j) = (P(i,j+1)-P(i,j)) / P(i,j) * 100
If the table contains only numeric values which is how it's described in the question, it would be easier to convert it to a matrix.
T = array2table(randi(10,6,18)); % 6x18 numeric table
P = T{:,:}; % Convert to matrix
% Compute percent increase across rows (6x17 result)
M = diff(P,1,2)./P(:,1:end-1)*100

2 Comments

Taole Tsoehlisi's answer moved here as a comment
Works perfectly thanks
Adam Danz
Adam Danz on 28 Aug 2020
Edited: Adam Danz on 29 Aug 2020
Glad I could help!

Sign in to comment.

More Answers (0)

Categories

Asked:

on 28 Aug 2020

Edited:

on 29 Aug 2020

Community Treasure Hunt

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

Start Hunting!