Calculate means of multiple matrices
Show older comments
Hi there, I'm new to Matlab and very bad in coding.
I have this set of matrices in my workspace named D01 - D09. There are 3 columns in each matrix.
First I want to extract the middle column and then calculate the mean by using 0.5*(min + max). The mean value is then stored as LiftD01 - LiftD09.
This is what I tried:
for k = 1:9
lift = D0{k}(:,2);
LiftD0{k} = 0.5*(min(lift)+max(lift));
end
However, the error "Index exceeds matrix dimensions." keeps popping out.
What should I do?
Thank you!
P.S. Is it correct to use matrixname{k} to make Matlab produce a sequence of matrices?
Answers (2)
Sean de Wolski
on 11 Aug 2011
Walter Roberson
on 11 Aug 2011
D0{3} is not the same thing as D03.
Before accessing D0{k} insert a line (outside the for loop)
[D0{1:9}] = deal(D01,D02,D03,D04,D05,D06,D07,D08,D09);
This will copy the contents of D01 to D0{1} (efficiently) but a change to D01 would not be reflected in D0{1} as they are not identical variables.
Categories
Find more on Matrix Indexing 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!