MATLAB Answers


Help with a for loop and matrices

Asked by Noah Wilson on 25 Jun 2019
Latest activity Answered by Rajat Gupta on 25 Jun 2019
I currently have this code where SizeChem is a 24x7 matrix and newcolum is a 24x1 matrix.
newcolumn = sum(SizeChem,2);
for i = 1:length(SizeChem)
T(i) = sum(newcolum(1:i,1));
I am wanting to create some arrays or variables that are the sum of the new column but summing one more row than the last. Then I want to take all those individual values and put them back into a matrix (24x1) starting with T{1} thru T{24}. I am also getting the error:
Undefined function or variable 'newcolum'.
Error in Analysis_plots (line 26)
T(i) = sum(newcolum(1:i,1));
I am not sure why this is. Thanks for the help in advanced.


Sign in to comment.




1 Answer

Answer by Rajat Gupta on 25 Jun 2019
 Accepted Answer

It should be newcolumn instead of newcolum in your loop body.


Sign in to comment.