필터 지우기
필터 지우기

Cell arrays inside a structure array - how to access and perform operations?

조회 수: 10 (최근 30일)
Hi,
I have a struct with a number of different fields. Some of these fields have two columns of cell arrays. Each cell array contains differently sized columns:
results.x{1,1} % has size 47x1
results.x{1,2} % has size 36x1
I need to:
1) Compute the mean of each cell.
2) Remove empty cells that might be found
3) Compute the mean of each column of cell arrays inside all fileds.
Not sure if I managed to clearly explain what I'm after. I've added a simplified exmaple file for clarity.
Any suggestion on how to approach this problem?

채택된 답변

David Hill
David Hill 2021년 1월 30일
I did not put x and t back into a struct.
a=find(ismember(isnan(results.timestamps),[1 1],'rows'),1)-1;%delete rows after
x=results.x(1:a,:);
t=results.timestamps(1:a,:);%does not seem you want to do anything with the timestamps
colmean=[mean(cell2mat(x(:,1))),mean(cell2mat(x(:,2)))];
cellmean=zeros(a,2);
for k=1:a
cellmean(k,1)=mean(x{k,1});
cellmean(k,2)=mean(x{k,2});
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by