mean of cells in loop with different dimensions

조회 수: 1 (최근 30일)
Nooshin Mahmoodi
Nooshin Mahmoodi 2018년 10월 20일
댓글: Image Analyst 2018년 10월 20일
I have a loop, and creat B{i,1} on it. now I need to calculate the mean of each cell.i used meanOfCities(i)= mean(cell2mat(B(i,1))) ; it workes just for 4 loop, and then this error : Index exceeds matrix dimensions. will occure.

채택된 답변

Image Analyst
Image Analyst 2018년 10월 20일
Inside the loop, right after you assigned B{i, 1} take the mean and assign that to a vector:
cellContents = B{i, 1}; % A vector, matrix, or higher dimensional array - whatever it is...
theMeans(i) = mean(cellContents(:));
Now, after your loop, theMeans will be the mean of every cell that you've assigned.
  댓글 수: 2
Nooshin Mahmoodi
Nooshin Mahmoodi 2018년 10월 20일
편집: Nooshin Mahmoodi 2018년 10월 20일
I need the loop, I have different i=1:9. how it workes without the loop? there is just one loop that I make B{i, 1} on it and then get mean
Image Analyst
Image Analyst 2018년 10월 20일
Without the loop, it really depends on what is in the cells. If all the cells contain the same size matrix you might be able to just use cell2mat() and then use mean().

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by