How to sum columns of multiple matrices?
9 views (last 30 days)
Sashank Jammalamadaka on 2 Feb 2017
I have 32 column matrices of different names to be added separately. Is it possible to write a loop to do it instead of writing Sum1 = sum(VarName2)... and so on for 32 matrices?
I have matrices named VarName2, VarName3, ..., VarName33. I tried using the following loop;
for i = 1:32
and it returned the error "Undefined function or variable 'VarName'". So, needed help with this.
Niels on 3 Feb 2017
Edited: Niels on 3 Feb 2017
for i= 1:32 % splitted command as string: sum(VarNamei)
final_sum=final_sum + evalin('base', ['sum(VarName', num2str(i) ,')']);
the sum of all vectors (if sum is used on a matrix, the result will be a row vector) ...
just tell me if it works, i had no problem using it.