Get the avarage for coresponding cell contents from a cell array
이전 댓글 표시
Hi,
I have two cell arrays.
- data = 1x175 cell (rows double array is not consistent for each cell. There are some cells which do not even have values.)
- Z1cell = 1x278 cell (each cell has a double array of 5479 rows)
I need to go through each cell of "data" and get the values for each cell, for example, data{1,1} has 272, 273,274. Then I need to get the corresponding cell from Z1cell, in this case, cell 272,273 and 274, and get the average for each row.
Hope I explained clearly.
Please see the two .mat files (data and Z1ccell) are attached.
Sample code I was trying is as follows but not working. Perhaps there may be an efficient way.
for k=1:175
[m]=data{1,k}
ave(:,k)=mean(Z1cell{1,m});
end
Thanks for the help in advance.
채택된 답변
추가 답변 (1개)
Image Analyst
2014년 10월 24일
0 개 추천
Because m could have a variable number of rows, that means the mean will have that same variable number of rows and "ave" will have that same variable number of columns. That means ave should be a cell array. You can make ave a double, but it must be at least as wide as the largest length you ever expect m to be and you must pre-allocate it, and then you need to adjust the second index of ave so that it's not k but 1:length(m), and you will have some empty aves that just remain zero. Having it be a cell array is probably simpler.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!