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?
0 件のコメント
採用された回答
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 Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!