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